ikraamkb commited on
Commit
908da90
·
verified ·
1 Parent(s): 4b92f75

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +30 -20
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
- # Create tabs for Document QA and Image QA
6
- with gr.Blocks() as demo:
7
- with gr.Tab("Document QA"):
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 home():
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="/")