File size: 1,800 Bytes
a135f37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
51
52
53
import gradio as gr
from rag_core import scrape_and_process_url, answer_question

# Global state to store the processing status
processing_status = ""

def process_url_and_update_status(url: str):
    global processing_status
    processing_status = "Processing... Please wait."
    gr.Info(processing_status)
    result = scrape_and_process_url(url)
    processing_status = result
    return processing_status

def get_answer_from_rag(question: str):
    if "Successfully scraped" not in processing_status:
        return "Please scrape and process a URL first before asking questions."
    return answer_question(question)

with gr.Blocks(title="RAG-Powered Documentation Assistant") as demo:
    gr.Markdown("# 📚 RAG-Powered Documentation Assistant\n\n"\
               "Enter a documentation URL, then ask questions about its content.")

    with gr.Row():
        with gr.Column(scale=2):
            url_input = gr.Textbox(label="Documentation URL", placeholder="e.g., https://docs.python.org/3/")
            process_button = gr.Button("Scrape & Process URL")
        with gr.Column(scale=1):
            status_output = gr.Markdown(value=processing_status, label="Processing Status")

    with gr.Row():
        with gr.Column(scale=2):
            question_input = gr.Textbox(label="Your Question", placeholder="e.g., How to define a function?")
            ask_button = gr.Button("Ask Question")
        with gr.Column(scale=1):
            answer_output = gr.Markdown(label="Answer")

    process_button.click(
        process_url_and_update_status,
        inputs=[url_input],
        outputs=[status_output]
    )

    ask_button.click(
        get_answer_from_rag,
        inputs=[question_input],
        outputs=[answer_output]
    )

if __name__ == "__main__":
    demo.launch()