Spaces:
Runtime error
Runtime error
jonathanlehner
commited on
Commit
·
cd40a85
1
Parent(s):
45e2b25
added simple gradio
Browse files
app.py
CHANGED
|
@@ -1,12 +1,29 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import random
|
| 3 |
|
| 4 |
+
def chat(message):
|
| 5 |
+
history = gr.get_state() or []
|
| 6 |
+
if message.startswith("How many"):
|
| 7 |
+
response = random.randint(1,10)
|
| 8 |
+
elif message.startswith("How"):
|
| 9 |
+
response = random.choice(["Great", "Good", "Okay", "Bad"])
|
| 10 |
+
elif message.startswith("Where"):
|
| 11 |
+
response = random.choice(["Here", "There", "Somewhere"])
|
| 12 |
+
else:
|
| 13 |
+
response = "I don't know"
|
| 14 |
+
history.append((message, response))
|
| 15 |
+
gr.set_state(history)
|
| 16 |
+
html = "<div class='chatbot'>"
|
| 17 |
+
for user_msg, resp_msg in history:
|
| 18 |
+
html += f"<div class='user_msg'>{user_msg}</div>"
|
| 19 |
+
html += f"<div class='resp_msg'>{resp_msg}</div>"
|
| 20 |
+
html += "</div>"
|
| 21 |
+
return html
|
| 22 |
|
| 23 |
+
iface = gr.Interface(chat, "text", "html", css="""
|
| 24 |
+
.chatbox {display:flex;flex-direction:column}
|
| 25 |
+
.user_msg, .resp_msg {padding:4px;margin-bottom:4px;border-radius:4px;width:80%}
|
| 26 |
+
.user_msg {background-color:cornflowerblue;color:white;align-self:start}
|
| 27 |
+
.resp_msg {background-color:lightgray;align-self:self-end}
|
| 28 |
+
""", allow_screenshot=False, allow_flagging=False)
|
| 29 |
+
iface.launch()
|