Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,15 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
from PIL import Image
|
|
|
|
|
4 |
|
5 |
-
# Load
|
6 |
summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
|
7 |
image_captioner = pipeline("image-to-text", model="nlpconnect/vit-gpt2-image-captioning")
|
8 |
|
9 |
-
|
|
|
10 |
|
11 |
def analyze_input(file, question=None):
|
12 |
if file is None:
|
@@ -58,6 +61,7 @@ def analyze_input(file, question=None):
|
|
58 |
else:
|
59 |
return "Unsupported file type. Please upload a valid image or document."
|
60 |
|
|
|
61 |
iface = gr.Interface(
|
62 |
fn=analyze_input,
|
63 |
inputs=gr.File(label="Upload Document or Image"),
|
@@ -66,7 +70,10 @@ iface = gr.Interface(
|
|
66 |
description="Upload a document (PDF, DOCX, PPTX, XLSX) to get a summary or an image to get a caption. Runs fully on CPU."
|
67 |
)
|
68 |
|
69 |
-
|
|
|
|
|
|
|
70 |
app = gr.mount_gradio_app(app, demo, path="/")
|
71 |
|
72 |
@app.get("/")
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
from PIL import Image
|
4 |
+
from fastapi import FastAPI
|
5 |
+
from starlette.responses import RedirectResponse
|
6 |
|
7 |
+
# Load models
|
8 |
summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
|
9 |
image_captioner = pipeline("image-to-text", model="nlpconnect/vit-gpt2-image-captioning")
|
10 |
|
11 |
+
# FastAPI app
|
12 |
+
app = FastAPI()
|
13 |
|
14 |
def analyze_input(file, question=None):
|
15 |
if file is None:
|
|
|
61 |
else:
|
62 |
return "Unsupported file type. Please upload a valid image or document."
|
63 |
|
64 |
+
# Gradio Interface
|
65 |
iface = gr.Interface(
|
66 |
fn=analyze_input,
|
67 |
inputs=gr.File(label="Upload Document or Image"),
|
|
|
70 |
description="Upload a document (PDF, DOCX, PPTX, XLSX) to get a summary or an image to get a caption. Runs fully on CPU."
|
71 |
)
|
72 |
|
73 |
+
# Wrap in TabbedInterface (even if only one for now)
|
74 |
+
demo = gr.TabbedInterface([iface], ["Docs and Images"])
|
75 |
+
|
76 |
+
# Mount to FastAPI app
|
77 |
app = gr.mount_gradio_app(app, demo, path="/")
|
78 |
|
79 |
@app.get("/")
|