SebastianSchramm commited on
Commit
902a0a9
·
1 Parent(s): d0b0fdf

first version

Browse files
Files changed (4) hide show
  1. .streamlit/config.toml +2 -0
  2. app.py +61 -0
  3. bot_avatar.jpeg +0 -0
  4. user_avatar.jpeg +0 -0
.streamlit/config.toml ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [theme]
2
+ base="dark"
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+ import time
3
+
4
+ import requests
5
+ import streamlit as st
6
+
7
+ random.seed(42)
8
+
9
+ backend_url = "https://sebastianschramm-qa-api.hf.space/answer/"
10
+
11
+ assistant_avatar = "bot_avatar.jpeg"
12
+ user_avatar = "user_avatar.jpeg"
13
+
14
+ st.set_page_config(page_title="Olympics 2024 Paris", page_icon=assistant_avatar)
15
+
16
+
17
+ def stream_bot_message(msg):
18
+ message_placeholder = st.empty()
19
+ displayed_message = ""
20
+
21
+ for char in msg:
22
+ displayed_message += char
23
+ message_placeholder.chat_message("assistant", avatar=assistant_avatar).write(
24
+ displayed_message
25
+ )
26
+ delay = random.randint(1, 8)
27
+ time.sleep(0.01 * delay)
28
+
29
+
30
+ svg_url = "https://eu.ftp.opendatasoft.com/paris2024/emblem-white.svg"
31
+ st.markdown(
32
+ f"""
33
+ <div style="display: flex; justify-content: center;">
34
+ <img src="{svg_url}" alt="SVG Image" style="width:20%; height:auto;">
35
+ </div>
36
+ """,
37
+ unsafe_allow_html=True,
38
+ )
39
+ st.title("FAQs Olympics 2024 Paris")
40
+ st.markdown(
41
+ "A chatbot for the Olympics 2024 in Paris. The tool is based on [open data](https://data.paris2024.org/pages/accueil/)"
42
+ )
43
+ if "messages" not in st.session_state:
44
+ st.session_state["messages"] = [
45
+ {"role": "assistant", "content": "How can I help you?"}
46
+ ]
47
+
48
+ for msg in st.session_state.messages:
49
+ st.chat_message(msg["role"], avatar=assistant_avatar).write(msg["content"])
50
+
51
+ if question := st.chat_input():
52
+ print(f"User question: {question}")
53
+ st.session_state.messages.append({"role": "user", "content": question})
54
+ st.chat_message("user", avatar=user_avatar).write(question)
55
+ response = requests.post(backend_url, json={"question": question})
56
+ print(response)
57
+ if response.status_code == 200:
58
+ msg = response.json()["answer"]
59
+ print(f"Bot answer: {msg}| Question was: {question}")
60
+ st.session_state.messages.append({"role": "agent", "content": msg})
61
+ stream_bot_message(msg)
bot_avatar.jpeg ADDED
user_avatar.jpeg ADDED