Spaces:
Sleeping
Sleeping
File size: 1,043 Bytes
0d80d9a 8c2963b 2d65d8a 0d80d9a 2d65d8a 8c2963b 2d65d8a 8c2963b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import os
import gradio as gr
import requests
from TwitterChatBot.main import ask
def get_answer(question):
answer = ask(question=question)
return answer.strip()
# def get_answer(question):
# try:
# answer = requests.get(
# url,
# json={"question": question},
# )
# except Exception as err:
# return f"Sorry there was a problem with {err}, please check your connection and try again."
# if answer.status_code == 200:
# return answer.json()["answer"]
# return "Sorry, We have a problem with our server"
def predict(input, history=[]):
answer = get_answer(input)
history.append((input, answer))
response = history
return response, history
with gr.Blocks() as demo:
chatbot = gr.Chatbot()
state = gr.State([])
with gr.Row():
txt = gr.Textbox(
show_label=False, placeholder="Enter text and press enter"
).style(container=False)
txt.submit(predict, [txt, state], [chatbot, state])
demo.launch()
|