Update app.py
Browse files
app.py
CHANGED
|
@@ -91,7 +91,7 @@ def extract_json(text: str) -> Dict[str, Any]:
|
|
| 91 |
return {"raw_output": text}
|
| 92 |
|
| 93 |
|
| 94 |
-
PROMPT = "Analyze this pantry image in detail, list every ingredient"
|
| 95 |
|
| 96 |
|
| 97 |
|
|
@@ -108,7 +108,7 @@ def analyze_pantry(image: Image.Image) -> Tuple[Image.Image, Dict[str, Any]]:
|
|
| 108 |
{
|
| 109 |
"role": "system",
|
| 110 |
"content": [
|
| 111 |
-
{"type": "text", "text": "
|
| 112 |
],
|
| 113 |
},
|
| 114 |
{
|
|
@@ -130,6 +130,7 @@ def analyze_pantry(image: Image.Image) -> Tuple[Image.Image, Dict[str, Any]]:
|
|
| 130 |
)
|
| 131 |
|
| 132 |
inputs = inputs.to(model.device)
|
|
|
|
| 133 |
|
| 134 |
with torch.inference_mode():
|
| 135 |
output_ids = model.generate(
|
|
@@ -145,6 +146,8 @@ def analyze_pantry(image: Image.Image) -> Tuple[Image.Image, Dict[str, Any]]:
|
|
| 145 |
clean_up_tokenization_spaces=False,
|
| 146 |
)[0].strip()
|
| 147 |
|
|
|
|
|
|
|
| 148 |
parsed = extract_json(generated_text)
|
| 149 |
if isinstance(parsed, dict) and "raw_output" not in parsed:
|
| 150 |
parsed["_raw_output"] = generated_text
|
|
@@ -154,9 +157,6 @@ def analyze_pantry(image: Image.Image) -> Tuple[Image.Image, Dict[str, Any]]:
|
|
| 154 |
|
| 155 |
with gr.Blocks() as demo:
|
| 156 |
gr.Markdown("# Pantry Scanner")
|
| 157 |
-
gr.Markdown(
|
| 158 |
-
"Single-image Qwen3-VL OCR/brand reader. No tiling, no crop pipeline, no manual sharpening."
|
| 159 |
-
)
|
| 160 |
|
| 161 |
with gr.Row():
|
| 162 |
image_input = gr.Image(type="pil", label="Pantry image")
|
|
|
|
| 91 |
return {"raw_output": text}
|
| 92 |
|
| 93 |
|
| 94 |
+
PROMPT = "Analyze this pantry image in detail, list every ingredient as JSON"
|
| 95 |
|
| 96 |
|
| 97 |
|
|
|
|
| 108 |
{
|
| 109 |
"role": "system",
|
| 110 |
"content": [
|
| 111 |
+
{"type": "text", "text": "Analyze this pantry image in detail, list every ingredient"}
|
| 112 |
],
|
| 113 |
},
|
| 114 |
{
|
|
|
|
| 130 |
)
|
| 131 |
|
| 132 |
inputs = inputs.to(model.device)
|
| 133 |
+
print("inputs:", inputs)
|
| 134 |
|
| 135 |
with torch.inference_mode():
|
| 136 |
output_ids = model.generate(
|
|
|
|
| 146 |
clean_up_tokenization_spaces=False,
|
| 147 |
)[0].strip()
|
| 148 |
|
| 149 |
+
print("generated_text:", generated_text)
|
| 150 |
+
|
| 151 |
parsed = extract_json(generated_text)
|
| 152 |
if isinstance(parsed, dict) and "raw_output" not in parsed:
|
| 153 |
parsed["_raw_output"] = generated_text
|
|
|
|
| 157 |
|
| 158 |
with gr.Blocks() as demo:
|
| 159 |
gr.Markdown("# Pantry Scanner")
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
with gr.Row():
|
| 162 |
image_input = gr.Image(type="pil", label="Pantry image")
|