ciditel commited on
Commit
9e803e1
1 Parent(s): 0ddb5fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -5
app.py CHANGED
@@ -43,8 +43,6 @@ def run_example(task_prompt, image, text_input=None, model_id='microsoft/Florenc
43
  prompt = task_prompt
44
  else:
45
  prompt = task_prompt + text_input
46
- iimage=image
47
- image=fig_to_pil(image)
48
  inputs = processor(text=prompt, images=image, return_tensors="pt").to("cuda")
49
  generated_ids = model.generate(
50
  input_ids=inputs["input_ids"],
@@ -118,7 +116,7 @@ def draw_ocr_bboxes(image, prediction):
118
  return image
119
 
120
  def process_image(image, task_prompt, text_input=None, model_id='microsoft/Florence-2-large'):
121
- image = Image.fromarray(image) # Convert NumPy array to PIL Image
122
  if task_prompt == 'Caption':
123
  task_prompt = '<CAPTION>'
124
  results = run_example(task_prompt, image, model_id=model_id)
@@ -193,13 +191,14 @@ def process_image(image, task_prompt, text_input=None, model_id='microsoft/Flore
193
 
194
 
195
  gradio_app_bill= gr.Interface(
196
- fn=run_example,
197
  inputs=[
 
198
  gr.Dropdown(choices=[
199
  'Caption', 'Detailed Caption', 'More Detailed Caption',
200
  'OCR', 'OCR with Region'
201
  ], label="Task Prompt", value= 'More Detailed Caption'),
202
- gr.Image(type='filepath'),
203
  gr.Textbox(label="Text Input (optional)"),
204
  gr.Dropdown(choices=list(models.keys()), label="Model", value='microsoft/Florence-2-large')
205
  ],
 
43
  prompt = task_prompt
44
  else:
45
  prompt = task_prompt + text_input
 
 
46
  inputs = processor(text=prompt, images=image, return_tensors="pt").to("cuda")
47
  generated_ids = model.generate(
48
  input_ids=inputs["input_ids"],
 
116
  return image
117
 
118
  def process_image(image, task_prompt, text_input=None, model_id='microsoft/Florence-2-large'):
119
+ image = Image.open(image) # Convert NumPy array to PIL Image
120
  if task_prompt == 'Caption':
121
  task_prompt = '<CAPTION>'
122
  results = run_example(task_prompt, image, model_id=model_id)
 
191
 
192
 
193
  gradio_app_bill= gr.Interface(
194
+ fn=process_image,
195
  inputs=[
196
+ gr.Image(type='filepath'),
197
  gr.Dropdown(choices=[
198
  'Caption', 'Detailed Caption', 'More Detailed Caption',
199
  'OCR', 'OCR with Region'
200
  ], label="Task Prompt", value= 'More Detailed Caption'),
201
+
202
  gr.Textbox(label="Text Input (optional)"),
203
  gr.Dropdown(choices=list(models.keys()), label="Model", value='microsoft/Florence-2-large')
204
  ],