Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from main import chat, index_url | |
| """Use text to call chat method from main.py""" | |
| def add_text(history, text): | |
| response = chat(question=text) | |
| response = response.encode("utf-8", "ignore").decode("utf-8") | |
| print(response) | |
| history = history + [(text, response)] | |
| return history, "" | |
| """Use text to call index_url method from main.py""" | |
| def add_url(history, url): | |
| data = index_url(url) | |
| response = "Found your data!" | |
| history = history + [(url, response)] | |
| return history, "" | |
| def bot(history): | |
| return history | |
| with gr.Blocks() as demo: | |
| chatbot = gr.Chatbot([], elem_id="chatbot").style(height=750) | |
| with gr.Row(): | |
| with gr.Column(scale=0.65): | |
| txt = gr.Textbox( | |
| show_label=False, | |
| placeholder="Enter text and press enter, or upload an image", | |
| ).style(container=False) | |
| with gr.Column(scale=0.35, min_width=0): | |
| url = gr.Textbox( | |
| show_label=False, | |
| placeholder="Enter url api endpoint", | |
| ).style(container=False) | |
| txt.submit(add_text, [chatbot, txt], [chatbot, txt]).then( | |
| bot, chatbot, chatbot | |
| ) | |
| url.submit(add_url, [chatbot, url], [chatbot, url]).then( | |
| bot, chatbot, chatbot | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |