jonathanlehner commited on
Commit
cd40a85
1 Parent(s): 45e2b25

added simple gradio

Browse files
Files changed (1) hide show
  1. app.py +26 -9
app.py CHANGED
@@ -1,12 +1,29 @@
1
  import gradio as gr
 
2
 
3
- description = "Story generation with GPT-2"
4
- title = "Talk to Peter!"
5
- examples = [["Peter:\ndo you like peanuts?"]]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
- interface = gr.Interface.load("huggingface/ethzanalytics/ai-msgbot-gpt2-M",
8
- description=description,
9
- examples=examples
10
- )
11
-
12
- interface.launch()
 
 
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()