Spaces:
Sleeping
Sleeping
| 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() | |