Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
-
from fastapi import FastAPI, UploadFile
|
|
|
|
| 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
|
| 85 |
# -------------------------
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
)
|
| 100 |
-
|
| 101 |
-
gr.TabbedInterface([doc_summary, img_caption], ["Summarize Document", "Caption Image"]).launch()
|
| 102 |
|
| 103 |
# -------------------------
|
| 104 |
-
#
|
| 105 |
# -------------------------
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
return {"message": "Gradio running at /docs or use CLI"}
|
| 109 |
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
| 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="/")
|