Spaces:
Sleeping
Sleeping
João Lima
commited on
Commit
·
9d1ba3e
1
Parent(s):
4598ede
fixing demo launch
Browse files
app.py
CHANGED
|
@@ -10,15 +10,15 @@ def load_document(file):
|
|
| 10 |
return "Please upload a PDF file."
|
| 11 |
try:
|
| 12 |
vectorstore = process_pdf(file.name)
|
| 13 |
-
return "Document processed successfully."
|
| 14 |
except Exception as e:
|
| 15 |
-
return f"Error: {str(e)}"
|
| 16 |
|
| 17 |
def ask(question):
|
| 18 |
if vectorstore is None:
|
| 19 |
-
return "Upload a document
|
| 20 |
if not question.strip():
|
| 21 |
-
return "
|
| 22 |
try:
|
| 23 |
return run_rag(question, vectorstore)
|
| 24 |
except Exception as e:
|
|
@@ -28,18 +28,20 @@ with gr.Blocks(title="Tech Explainer RAG") as demo:
|
|
| 28 |
gr.Markdown("# Tech Explainer — RAG with Automatic Evaluation")
|
| 29 |
|
| 30 |
file = gr.File(label="Upload PDF", file_types=[".pdf"])
|
| 31 |
-
load_btn = gr.Button("Process PDF")
|
| 32 |
-
status = gr.Textbox(label="Status")
|
|
|
|
|
|
|
| 33 |
|
| 34 |
question = gr.Textbox(label="Question", placeholder="Ask a question about the document...")
|
| 35 |
-
ask_btn = gr.Button("Ask")
|
| 36 |
|
| 37 |
-
answer = gr.Textbox(label="Answer", lines=5)
|
| 38 |
-
sources = gr.Textbox(label="Sources", lines=2)
|
| 39 |
-
evaluation = gr.Textbox(label="Evaluation", lines=3)
|
| 40 |
|
| 41 |
load_btn.click(load_document, inputs=file, outputs=status)
|
| 42 |
ask_btn.click(ask, inputs=question, outputs=[answer, sources, evaluation])
|
| 43 |
|
| 44 |
if __name__ == "__main__":
|
| 45 |
-
demo.launch()
|
|
|
|
| 10 |
return "Please upload a PDF file."
|
| 11 |
try:
|
| 12 |
vectorstore = process_pdf(file.name)
|
| 13 |
+
return "✓ Document processed successfully."
|
| 14 |
except Exception as e:
|
| 15 |
+
return f"❌ Error: {str(e)}"
|
| 16 |
|
| 17 |
def ask(question):
|
| 18 |
if vectorstore is None:
|
| 19 |
+
return "Upload a document", "", ""
|
| 20 |
if not question.strip():
|
| 21 |
+
return "Enter a question", "", ""
|
| 22 |
try:
|
| 23 |
return run_rag(question, vectorstore)
|
| 24 |
except Exception as e:
|
|
|
|
| 28 |
gr.Markdown("# Tech Explainer — RAG with Automatic Evaluation")
|
| 29 |
|
| 30 |
file = gr.File(label="Upload PDF", file_types=[".pdf"])
|
| 31 |
+
load_btn = gr.Button("Process PDF", variant="primary")
|
| 32 |
+
status = gr.Textbox(label="Status", interactive=False)
|
| 33 |
+
|
| 34 |
+
gr.Markdown("---")
|
| 35 |
|
| 36 |
question = gr.Textbox(label="Question", placeholder="Ask a question about the document...")
|
| 37 |
+
ask_btn = gr.Button("Ask", variant="primary")
|
| 38 |
|
| 39 |
+
answer = gr.Textbox(label="Answer", lines=5, interactive=False)
|
| 40 |
+
sources = gr.Textbox(label="Sources", lines=2, interactive=False)
|
| 41 |
+
evaluation = gr.Textbox(label="Evaluation", lines=3, interactive=False)
|
| 42 |
|
| 43 |
load_btn.click(load_document, inputs=file, outputs=status)
|
| 44 |
ask_btn.click(ask, inputs=question, outputs=[answer, sources, evaluation])
|
| 45 |
|
| 46 |
if __name__ == "__main__":
|
| 47 |
+
demo.queue().launch()
|