Spaces:
Sleeping
Sleeping
Ronti Patange commited on
Commit ·
347d0b0
1
Parent(s): 9e1643c
Surface exception details in analyze() response for debugging
Browse files
app.py
CHANGED
|
@@ -89,21 +89,25 @@ def analyze(image_b64: str, extra_notes: str, api_key: str) -> str:
|
|
| 89 |
],
|
| 90 |
}]
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
|
| 109 |
demo = gr.Interface(
|
|
|
|
| 89 |
],
|
| 90 |
}]
|
| 91 |
|
| 92 |
+
try:
|
| 93 |
+
inputs = processor.apply_chat_template(
|
| 94 |
+
messages,
|
| 95 |
+
tokenize=True,
|
| 96 |
+
add_generation_prompt=True,
|
| 97 |
+
return_dict=True,
|
| 98 |
+
return_tensors="pt",
|
| 99 |
+
).to("cuda")
|
| 100 |
+
|
| 101 |
+
model.to("cuda")
|
| 102 |
+
with torch.no_grad():
|
| 103 |
+
output_ids = model.generate(**inputs, max_new_tokens=900, do_sample=False)
|
| 104 |
+
|
| 105 |
+
generated = output_ids[0][inputs.input_ids.shape[1]:]
|
| 106 |
+
raw = processor.decode(generated, skip_special_tokens=True)
|
| 107 |
+
return _extract_json(raw)
|
| 108 |
+
except Exception as e:
|
| 109 |
+
import traceback
|
| 110 |
+
return json.dumps({"error": f"{type(e).__name__}: {e}", "trace": traceback.format_exc()[-1500:]})
|
| 111 |
|
| 112 |
|
| 113 |
demo = gr.Interface(
|