File size: 989 Bytes
0d061c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)