Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import requests | |
| from config import backend_url | |
| def ask_from_url(url, question): | |
| payload = { | |
| "url": url, | |
| "question": question | |
| } | |
| with requests.post( | |
| f"{backend_url}/api/gemini/process-url", | |
| json=payload, | |
| stream= True | |
| ) as res: | |
| if res.status_code!= 200: | |
| yield f"Error: {res.text}" | |
| return | |
| reply = "" | |
| for chunk in res.iter_content(chunk_size=None, decode_unicode=True): | |
| reply += chunk | |
| yield reply | |
| def create_url_tab(): | |
| with gr.Tab("Ask from URL"): | |
| url_input = gr.Textbox(label="Website Url") | |
| url_question = gr.Textbox(label="Your question") | |
| answer = gr.Textbox(label="Reply of Chatbot") | |
| btn = gr.Button("Ask") | |
| btn.click(ask_from_url, [url_input, url_question], answer) | |
| url_question.submit(ask_from_url, [url_input, url_question], answer) |