Spaces:
Sleeping
Sleeping
initial commit
Browse files- .gitignore +2 -0
- app.py +38 -0
- requirements.txt +1 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
.env
|
2 |
+
env/
|
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
|
4 |
+
|
5 |
+
def get_answer(question):
|
6 |
+
try:
|
7 |
+
answer = requests.get(
|
8 |
+
"http://127.0.0.1:8000/api/",
|
9 |
+
json={"question": question},
|
10 |
+
)
|
11 |
+
except Exception as err:
|
12 |
+
return f"Sorry there was a problem with {err}, please check your connection and try again."
|
13 |
+
|
14 |
+
if answer.status_code == 200:
|
15 |
+
return answer.json()["answer"]
|
16 |
+
|
17 |
+
return "Sorry, We have a problem with our server"
|
18 |
+
|
19 |
+
|
20 |
+
def predict(input, history=[]):
|
21 |
+
answer = get_answer(input)
|
22 |
+
history.append((input, answer))
|
23 |
+
response = history
|
24 |
+
return response, history
|
25 |
+
|
26 |
+
|
27 |
+
with gr.Blocks() as demo:
|
28 |
+
chatbot = gr.Chatbot()
|
29 |
+
state = gr.State([])
|
30 |
+
|
31 |
+
with gr.Row():
|
32 |
+
txt = gr.Textbox(
|
33 |
+
show_label=False, placeholder="Enter text and press enter"
|
34 |
+
).style(container=False)
|
35 |
+
|
36 |
+
txt.submit(predict, [txt, state], [chatbot, state])
|
37 |
+
|
38 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
gradio
|