File size: 1,258 Bytes
908da90
 
850c784
 
908da90
 
850c784
908da90
 
 
 
 
 
 
 
52e04fe
 
908da90
 
 
 
 
 
 
52e04fe
 
908da90
 
 
 
 
4b92f75
 
 
908da90
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from fastapi import FastAPI
from fastapi.responses import RedirectResponse
import gradio as gr

from app import answer_question_from_doc
from appImage import answer_question_from_image

app = FastAPI()

# === Document QA Tab ===
with gr.Blocks() as doc_interface:
    gr.Markdown("## ๐Ÿ“„ Document QA")
    doc_file = gr.File(label="Upload File (PDF, DOCX, PPTX, XLSX)")
    doc_question = gr.Textbox(label="Ask a question")
    doc_answer = gr.Textbox(label="Answer")
    doc_submit = gr.Button("Get Answer")
    doc_submit.click(fn=answer_question_from_doc, inputs=[doc_file, doc_question], outputs=doc_answer)

# === Image QA Tab ===
with gr.Blocks() as img_interface:
    gr.Markdown("## ๐Ÿ–ผ๏ธ Image QA")
    img_input = gr.Image(label="Upload an Image")
    img_question = gr.Textbox(label="Ask a question")
    img_answer = gr.Textbox(label="Answer")
    img_submit = gr.Button("Get Answer")
    img_submit.click(fn=answer_question_from_image, inputs=[img_input, img_question], outputs=img_answer)

# === Combine Tabs ===
demo = gr.TabbedInterface([doc_interface, img_interface], tab_names=["Document QA", "Image QA"])

# Mount Gradio App
app = gr.mount_gradio_app(app, demo, path="/")

@app.get("/")
def root():
    return RedirectResponse(url="/")