zinoubm's picture
adding the url to env
0d80d9a
raw
history blame
965 Bytes
import os
import gradio as gr
import requests
from dotenv import load_dotenv
load_dotenv()
url = os.getenv("URL")
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()