Spaces:
Running
Running
| import gradio as gr | |
| from scraper import scrape_url | |
| from utils import chunk_text | |
| from embedder import VectorStore | |
| from llm import generate_answer | |
| def rag_pipeline(url, question): | |
| try: | |
| # 1. Scrape | |
| text = scrape_url(url) | |
| if not text.strip(): | |
| return "β Failed to extract content. Try another site." | |
| # 2. Chunk | |
| chunks = chunk_text(text) | |
| if len(chunks) == 0: | |
| return "β No usable content found." | |
| # 3. Embed | |
| vector_store = VectorStore() | |
| vector_store.create_index(chunks) | |
| # 4. Retrieve | |
| context_chunks = vector_store.retrieve(question) | |
| context = "\n".join(context_chunks) | |
| # 5. Generate | |
| answer = generate_answer(context, question) | |
| return answer | |
| except Exception as e: | |
| return f"β Error: {str(e)}" | |
| iface = gr.Interface( | |
| fn=rag_pipeline, | |
| inputs=[ | |
| gr.Textbox(label="π Website URL"), | |
| gr.Textbox(label="β Ask a Question") | |
| ], | |
| outputs=gr.Textbox(label="π€ Answer"), | |
| title="π Web RAG Chatbot", | |
| description="Ask questions about any website using AI" | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() |