Spaces:
Running
Running
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="/") | |
def root(): | |
return RedirectResponse(url="/") | |