ARCQUB commited on
Commit
72c589b
·
verified ·
1 Parent(s): 5f5b090

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -17
app.py CHANGED
@@ -89,7 +89,7 @@ def format_pretty_view(output):
89
  for g in process["gateways"]:
90
  name = g.get("name", "")
91
  type_ = g.get("type", "")
92
- label = g.get("label", "") # some outputs may use 'label'
93
  desc = g.get("description", "")
94
  line = f" - {name}"
95
  if type_:
@@ -138,21 +138,11 @@ def format_pretty_view(output):
138
  return "\n".join(lines).strip()
139
 
140
  # === Main Inference Handler
141
- def process_single_image(model_name, image_file, api_key_file=None):
142
  runner = load_model_runner(model_name)
143
  image = Image.open(image_file.name).convert("RGB")
144
 
145
- api_key = None
146
- if model_name == "GPT-4o" and api_key_file is not None:
147
- try:
148
- api_key = open(api_key_file.name, "r").read().strip()
149
- except Exception as e:
150
- return image, "(API key file could not be read)", f"(Error: {e})"
151
-
152
- if model_name == "GPT-4o":
153
- result = runner(image, api_key=api_key)
154
- else:
155
- result = runner(image)
156
 
157
  parsed_json = result.get("json")
158
  raw_text = result.get("raw", "")
@@ -166,13 +156,12 @@ def process_single_image(model_name, image_file, api_key_file=None):
166
 
167
  return image, json_output, pretty_output
168
 
169
- # === Gradio Interface (Simple)
170
  iface = gr.Interface(
171
  fn=process_single_image,
172
  inputs=[
173
  gr.Dropdown(choices=list(MODEL_MAP.keys()), label="Select Vision Model"),
174
- gr.File(file_types=["image"], label="Upload a BPMN Image"),
175
- gr.File(file_types=[".txt"], label="🔐 Upload OpenAI API Key File (only for GPT-4o)")
176
  ],
177
  outputs=[
178
  gr.Image(label="Input Image"),
@@ -180,7 +169,7 @@ iface = gr.Interface(
180
  gr.Textbox(label="Prettified View (User-Friendly)", lines=25)
181
  ],
182
  title="🖼️ Vision Model Extractor - JSON + Pretty View",
183
- description="Upload a BPMN image and select a vision model to extract structured output. API key file is required only for GPT-4o.",
184
  allow_flagging="never"
185
  )
186
 
 
89
  for g in process["gateways"]:
90
  name = g.get("name", "")
91
  type_ = g.get("type", "")
92
+ label = g.get("label", "")
93
  desc = g.get("description", "")
94
  line = f" - {name}"
95
  if type_:
 
138
  return "\n".join(lines).strip()
139
 
140
  # === Main Inference Handler
141
+ def process_single_image(model_name, image_file):
142
  runner = load_model_runner(model_name)
143
  image = Image.open(image_file.name).convert("RGB")
144
 
145
+ result = runner(image)
 
 
 
 
 
 
 
 
 
 
146
 
147
  parsed_json = result.get("json")
148
  raw_text = result.get("raw", "")
 
156
 
157
  return image, json_output, pretty_output
158
 
159
+ # === Gradio Interface
160
  iface = gr.Interface(
161
  fn=process_single_image,
162
  inputs=[
163
  gr.Dropdown(choices=list(MODEL_MAP.keys()), label="Select Vision Model"),
164
+ gr.File(file_types=["image"], label="Upload a BPMN Image")
 
165
  ],
166
  outputs=[
167
  gr.Image(label="Input Image"),
 
169
  gr.Textbox(label="Prettified View (User-Friendly)", lines=25)
170
  ],
171
  title="🖼️ Vision Model Extractor - JSON + Pretty View",
172
+ description="Upload a BPMN image and select a vision model to extract structured output. GPT-4o uses an API key from your Hugging Face Space Secret.",
173
  allow_flagging="never"
174
  )
175