ikraamkb commited on
Commit
5b4fc38
ยท
verified ยท
1 Parent(s): b01d6ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -25
app.py CHANGED
@@ -1,4 +1,5 @@
1
- from fastapi import FastAPI, UploadFile, File
 
2
  import fitz # PyMuPDF
3
  import docx
4
  import openpyxl
@@ -64,7 +65,6 @@ def summarize_document(file: UploadFile):
64
  if not text.strip():
65
  return "No extractable text."
66
 
67
- # Trim large docs
68
  text = text[:3000]
69
  try:
70
  summary = summarizer(text, max_length=150, min_length=30, do_sample=False)
@@ -81,31 +81,28 @@ def interpret_image(image):
81
  return f"Image captioning error: {e}"
82
 
83
  # -------------------------
84
- # Gradio UI
85
  # -------------------------
86
- def run_interface():
87
- doc_summary = gr.Interface(
88
- fn=summarize_document,
89
- inputs=gr.File(label="Upload a Document"),
90
- outputs="text",
91
- title="๐Ÿ“„ Document Summarizer"
92
- )
93
-
94
- img_caption = gr.Interface(
95
- fn=interpret_image,
96
- inputs=gr.Image(type="pil", label="Upload an Image"),
97
- outputs="text",
98
- title="๐Ÿ–ผ๏ธ Image Interpreter"
99
- )
100
-
101
- gr.TabbedInterface([doc_summary, img_caption], ["Summarize Document", "Caption Image"]).launch()
102
 
103
  # -------------------------
104
- # Run from CLI or FastAPI
105
  # -------------------------
106
- @app.get("/")
107
- def read_root():
108
- return {"message": "Gradio running at /docs or use CLI"}
109
 
110
- if __name__ == "__main__":
111
- run_interface()
 
 
1
+ from fastapi import FastAPI, UploadFile
2
+ from fastapi.responses import RedirectResponse
3
  import fitz # PyMuPDF
4
  import docx
5
  import openpyxl
 
65
  if not text.strip():
66
  return "No extractable text."
67
 
 
68
  text = text[:3000]
69
  try:
70
  summary = summarizer(text, max_length=150, min_length=30, do_sample=False)
 
81
  return f"Image captioning error: {e}"
82
 
83
  # -------------------------
84
+ # Gradio Interfaces
85
  # -------------------------
86
+ doc_summary = gr.Interface(
87
+ fn=summarize_document,
88
+ inputs=gr.File(label="Upload a Document"),
89
+ outputs="text",
90
+ title="๐Ÿ“„ Document Summarizer"
91
+ )
92
+
93
+ img_caption = gr.Interface(
94
+ fn=interpret_image,
95
+ inputs=gr.Image(type="pil", label="Upload an Image"),
96
+ outputs="text",
97
+ title="๐Ÿ–ผ๏ธ Image Interpreter"
98
+ )
 
 
 
99
 
100
  # -------------------------
101
+ # Combine into Gradio + FastAPI
102
  # -------------------------
103
+ demo = gr.TabbedInterface([doc_summary, img_caption], ["Document QA", "Image QA"])
104
+ app = gr.mount_gradio_app(app, demo, path="/")
 
105
 
106
+ @app.get("/")
107
+ def home():
108
+ return RedirectResponse(url="/")