Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
-
# app.py β Gradio
|
| 2 |
|
| 3 |
import base64
|
|
|
|
| 4 |
import threading
|
| 5 |
import time
|
| 6 |
import urllib.parse
|
|
@@ -18,6 +19,8 @@ from transformers import (
|
|
| 18 |
T5Tokenizer,
|
| 19 |
)
|
| 20 |
|
|
|
|
|
|
|
| 21 |
device = torch.device("cpu")
|
| 22 |
|
| 23 |
IMG_MODEL = "nlpconnect/vit-gpt2-image-captioning"
|
|
@@ -32,7 +35,6 @@ rewriter = T5ForConditionalGeneration.from_pretrained(TXT_MODEL).to(device).eval
|
|
| 32 |
|
| 33 |
|
| 34 |
def load_image(url: str):
|
| 35 |
-
"""Return (PIL.Image, None) or (None, error). Handles http/https and dataβURL."""
|
| 36 |
try:
|
| 37 |
url = (url or "").strip()
|
| 38 |
if not url:
|
|
@@ -137,7 +139,7 @@ def final_caption(url, prompt, detail, beams, sample):
|
|
| 137 |
|
| 138 |
|
| 139 |
css = "footer {display:none !important;}"
|
| 140 |
-
with gr.Blocks() as demo:
|
| 141 |
gr.Markdown("## Image Describer")
|
| 142 |
with gr.Row():
|
| 143 |
with gr.Column():
|
|
@@ -167,4 +169,17 @@ with gr.Blocks() as demo:
|
|
| 167 |
|
| 168 |
if __name__ == "__main__":
|
| 169 |
demo.queue()
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py β Gradio 6+ (CPU) β SSE / SSR-safe
|
| 2 |
|
| 3 |
import base64
|
| 4 |
+
import logging
|
| 5 |
import threading
|
| 6 |
import time
|
| 7 |
import urllib.parse
|
|
|
|
| 19 |
T5Tokenizer,
|
| 20 |
)
|
| 21 |
|
| 22 |
+
logging.basicConfig(level=logging.INFO)
|
| 23 |
+
|
| 24 |
device = torch.device("cpu")
|
| 25 |
|
| 26 |
IMG_MODEL = "nlpconnect/vit-gpt2-image-captioning"
|
|
|
|
| 35 |
|
| 36 |
|
| 37 |
def load_image(url: str):
|
|
|
|
| 38 |
try:
|
| 39 |
url = (url or "").strip()
|
| 40 |
if not url:
|
|
|
|
| 139 |
|
| 140 |
|
| 141 |
css = "footer {display:none !important;}"
|
| 142 |
+
with gr.Blocks(title="Image Describer (CPU)") as demo:
|
| 143 |
gr.Markdown("## Image Describer")
|
| 144 |
with gr.Row():
|
| 145 |
with gr.Column():
|
|
|
|
| 169 |
|
| 170 |
if __name__ == "__main__":
|
| 171 |
demo.queue()
|
| 172 |
+
try:
|
| 173 |
+
demo.launch(
|
| 174 |
+
server_name="0.0.0.0",
|
| 175 |
+
server_port=7860,
|
| 176 |
+
css=css,
|
| 177 |
+
prevent_thread_lock=True,
|
| 178 |
+
ssr_mode=False, # disable server-side rendering (avoids SSE/SSR SSE issues)
|
| 179 |
+
share=False,
|
| 180 |
+
)
|
| 181 |
+
except Exception as e:
|
| 182 |
+
logging.exception("Launch failed")
|
| 183 |
+
with open("/tmp/gradio_launch_err.txt", "w") as fh:
|
| 184 |
+
fh.write(str(e))
|
| 185 |
+
raise
|