Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from rag_core import scrape_and_process_url, answer_question
|
| 3 |
+
|
| 4 |
+
# Global state to store the processing status
|
| 5 |
+
processing_status = ""
|
| 6 |
+
|
| 7 |
+
def process_url_and_update_status(url: str):
|
| 8 |
+
global processing_status
|
| 9 |
+
processing_status = "Processing... Please wait."
|
| 10 |
+
gr.Info(processing_status)
|
| 11 |
+
result = scrape_and_process_url(url)
|
| 12 |
+
processing_status = result
|
| 13 |
+
return processing_status
|
| 14 |
+
|
| 15 |
+
def get_answer_from_rag(question: str):
|
| 16 |
+
if "Successfully scraped" not in processing_status:
|
| 17 |
+
return "Please scrape and process a URL first before asking questions."
|
| 18 |
+
return answer_question(question)
|
| 19 |
+
|
| 20 |
+
with gr.Blocks(title="RAG-Powered Documentation Assistant") as demo:
|
| 21 |
+
gr.Markdown("# 📚 RAG-Powered Documentation Assistant\n\n"\
|
| 22 |
+
"Enter a documentation URL, then ask questions about its content.")
|
| 23 |
+
|
| 24 |
+
with gr.Row():
|
| 25 |
+
with gr.Column(scale=2):
|
| 26 |
+
url_input = gr.Textbox(label="Documentation URL", placeholder="e.g., https://docs.python.org/3/")
|
| 27 |
+
process_button = gr.Button("Scrape & Process URL")
|
| 28 |
+
with gr.Column(scale=1):
|
| 29 |
+
status_output = gr.Markdown(value=processing_status, label="Processing Status")
|
| 30 |
+
|
| 31 |
+
with gr.Row():
|
| 32 |
+
with gr.Column(scale=2):
|
| 33 |
+
question_input = gr.Textbox(label="Your Question", placeholder="e.g., How to define a function?")
|
| 34 |
+
ask_button = gr.Button("Ask Question")
|
| 35 |
+
with gr.Column(scale=1):
|
| 36 |
+
answer_output = gr.Markdown(label="Answer")
|
| 37 |
+
|
| 38 |
+
process_button.click(
|
| 39 |
+
process_url_and_update_status,
|
| 40 |
+
inputs=[url_input],
|
| 41 |
+
outputs=[status_output]
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
ask_button.click(
|
| 45 |
+
get_answer_from_rag,
|
| 46 |
+
inputs=[question_input],
|
| 47 |
+
outputs=[answer_output]
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
if __name__ == "__main__":
|
| 51 |
+
demo.launch()
|
| 52 |
+
|