Spaces:
Sleeping
Sleeping
adding final touches
Browse files
app.py
CHANGED
|
@@ -1,8 +1,16 @@
|
|
| 1 |
-
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
import requests
|
| 4 |
from TwitterChatBot.main import ask
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def get_answer(question):
|
| 8 |
print(question)
|
|
@@ -10,21 +18,6 @@ def get_answer(question):
|
|
| 10 |
return answer.strip()
|
| 11 |
|
| 12 |
|
| 13 |
-
# def get_answer(question):
|
| 14 |
-
# try:
|
| 15 |
-
# answer = requests.get(
|
| 16 |
-
# url,
|
| 17 |
-
# json={"question": question},
|
| 18 |
-
# )
|
| 19 |
-
# except Exception as err:
|
| 20 |
-
# return f"Sorry there was a problem with {err}, please check your connection and try again."
|
| 21 |
-
|
| 22 |
-
# if answer.status_code == 200:
|
| 23 |
-
# return answer.json()["answer"]
|
| 24 |
-
|
| 25 |
-
# return "Sorry, We have a problem with our server"
|
| 26 |
-
|
| 27 |
-
|
| 28 |
def predict(input, history=[]):
|
| 29 |
answer = get_answer(input)
|
| 30 |
history.append((input, answer))
|
|
@@ -33,12 +26,13 @@ def predict(input, history=[]):
|
|
| 33 |
|
| 34 |
|
| 35 |
with gr.Blocks() as demo:
|
|
|
|
| 36 |
chatbot = gr.Chatbot()
|
| 37 |
state = gr.State([])
|
| 38 |
|
| 39 |
with gr.Row():
|
| 40 |
txt = gr.Textbox(
|
| 41 |
-
show_label=False, placeholder="
|
| 42 |
).style(container=False)
|
| 43 |
|
| 44 |
txt.submit(predict, [txt, state], [chatbot, state])
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from TwitterChatBot.main import ask
|
| 3 |
|
| 4 |
+
title = "Car Seats Voice Commands"
|
| 5 |
+
|
| 6 |
+
link = "https://cdn.cms-twdigitalassets.com/content/dam/legal-twitter/asset-download-files/TheTwitterUserAgreement_1.pdf"
|
| 7 |
+
|
| 8 |
+
description = f"""
|
| 9 |
+
# Twitter Terms Of Service ChatBot
|
| 10 |
+
This chatbot answers questions about **Twitter terms of service** based on this [resource]({link}), The techniques used in this project
|
| 11 |
+
can be used to answer questions from any kind of business or legal document.
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
|
| 15 |
def get_answer(question):
|
| 16 |
print(question)
|
|
|
|
| 18 |
return answer.strip()
|
| 19 |
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
def predict(input, history=[]):
|
| 22 |
answer = get_answer(input)
|
| 23 |
history.append((input, answer))
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
with gr.Blocks() as demo:
|
| 29 |
+
gr.Markdown(description)
|
| 30 |
chatbot = gr.Chatbot()
|
| 31 |
state = gr.State([])
|
| 32 |
|
| 33 |
with gr.Row():
|
| 34 |
txt = gr.Textbox(
|
| 35 |
+
show_label=False, placeholder="Ask me a question and press enter"
|
| 36 |
).style(container=False)
|
| 37 |
|
| 38 |
txt.submit(predict, [txt, state], [chatbot, state])
|