Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -1,26 +1,36 @@
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
-
from app import answer_question_from_doc # Assuming `answer_question_from_doc` is in app.py
|
3 |
-
from appImage import answer_question_from_image # Assuming `answer_question_from_image` is in appImage.py
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
-
|
8 |
-
gr.Markdown("### Document Question Answering")
|
9 |
-
file_input = gr.File(label="Upload PDF")
|
10 |
-
question_input = gr.Textbox(label="Ask a Question")
|
11 |
-
file_output = gr.Textbox(label="Answer")
|
12 |
-
file_input.change(answer_question_from_doc, [file_input, question_input], file_output)
|
13 |
-
|
14 |
-
with gr.Tab("Image QA"):
|
15 |
-
gr.Markdown("### Image Question Answering")
|
16 |
-
img_input = gr.Image(label="Upload Image")
|
17 |
-
img_question_input = gr.Textbox(label="Ask a Question")
|
18 |
-
img_output = gr.Textbox(label="Answer")
|
19 |
-
img_input.change(answer_question_from_image, [img_input, img_question_input], img_output)
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
app = gr.mount_gradio_app(app, demo, path="/")
|
22 |
|
23 |
-
# Root redirect to Gradio app
|
24 |
@app.get("/")
|
25 |
-
def
|
26 |
-
return RedirectResponse(url="/")
|
|
|
1 |
+
# main.py
|
2 |
+
from fastapi import FastAPI
|
3 |
+
from fastapi.responses import RedirectResponse
|
4 |
import gradio as gr
|
|
|
|
|
5 |
|
6 |
+
# ✅ Import your QA functions from app.py and appImage.py
|
7 |
+
from app import answer_question_from_doc
|
8 |
+
from appImage import answer_question_from_image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
+
app = FastAPI()
|
11 |
+
|
12 |
+
# === Document QA Tab ===
|
13 |
+
with gr.Blocks() as doc_interface:
|
14 |
+
gr.Markdown("## 📄 Document QA")
|
15 |
+
doc_file = gr.File(label="Upload File (PDF, DOCX, PPTX, XLSX)")
|
16 |
+
doc_question = gr.Textbox(label="Ask a question")
|
17 |
+
doc_answer = gr.Textbox(label="Answer")
|
18 |
+
doc_file.change(fn=answer_question_from_doc, inputs=[doc_file, doc_question], outputs=doc_answer)
|
19 |
+
|
20 |
+
# === Image QA Tab ===
|
21 |
+
with gr.Blocks() as img_interface:
|
22 |
+
gr.Markdown("## 🖼️ Image QA")
|
23 |
+
img_input = gr.Image(label="Upload an Image")
|
24 |
+
img_question = gr.Textbox(label="Ask a question")
|
25 |
+
img_answer = gr.Textbox(label="Answer")
|
26 |
+
img_input.change(fn=answer_question_from_image, inputs=[img_input, img_question], outputs=img_answer)
|
27 |
+
|
28 |
+
# === Combine Tabs ===
|
29 |
+
demo = gr.TabbedInterface([doc_interface, img_interface], tab_names=["Document QA", "Image QA"])
|
30 |
+
|
31 |
+
# Mount Gradio App
|
32 |
app = gr.mount_gradio_app(app, demo, path="/")
|
33 |
|
|
|
34 |
@app.get("/")
|
35 |
+
def root():
|
36 |
+
return RedirectResponse(url="/")
|