Update app.py
Browse files
app.py
CHANGED
|
@@ -21,21 +21,23 @@ def generate_alt_text(files, max_new_tokens):
|
|
| 21 |
"""
|
| 22 |
captions = []
|
| 23 |
for path in files or []:
|
| 24 |
-
# Read image bytes
|
| 25 |
with open(path, "rb") as fin:
|
| 26 |
img_bytes = fin.read()
|
| 27 |
-
# Invoke the hosted model
|
| 28 |
response = inference(
|
| 29 |
inputs=img_bytes,
|
| 30 |
-
|
| 31 |
request_format="binary"
|
| 32 |
)
|
| 33 |
-
# Extract
|
| 34 |
text = response[0].get("generated_text", "").strip()
|
| 35 |
if text:
|
| 36 |
text = text[0].upper() + text[1:]
|
| 37 |
captions.append(text)
|
| 38 |
-
return "
|
|
|
|
|
|
|
| 39 |
|
| 40 |
# --- Gradio Interface ---
|
| 41 |
with gr.Blocks(title="Qwen2.5-VL-7B via Inference API") as demo:
|
|
|
|
| 21 |
"""
|
| 22 |
captions = []
|
| 23 |
for path in files or []:
|
| 24 |
+
# Read image bytes
|
| 25 |
with open(path, "rb") as fin:
|
| 26 |
img_bytes = fin.read()
|
| 27 |
+
# Invoke the hosted model (use 'params' instead of 'parameters')
|
| 28 |
response = inference(
|
| 29 |
inputs=img_bytes,
|
| 30 |
+
params={"max_new_tokens": int(max_new_tokens)},
|
| 31 |
request_format="binary"
|
| 32 |
)
|
| 33 |
+
# Extract generated text
|
| 34 |
text = response[0].get("generated_text", "").strip()
|
| 35 |
if text:
|
| 36 |
text = text[0].upper() + text[1:]
|
| 37 |
captions.append(text)
|
| 38 |
+
return "
|
| 39 |
+
|
| 40 |
+
".join(captions) "\n\n".join(captions)
|
| 41 |
|
| 42 |
# --- Gradio Interface ---
|
| 43 |
with gr.Blocks(title="Qwen2.5-VL-7B via Inference API") as demo:
|