J-LAB commited on
Commit
84d0e49
·
verified ·
1 Parent(s): 628b60d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -122,14 +122,24 @@ def process_image(image, task_prompt, text_input=None, model_id='J-LAB/Florence_
122
  if task_prompt == 'Product Caption':
123
  task_prompt = '<PC>'
124
  results = run_example(task_prompt, image, model_id=model_id)
125
- return results, None
126
  elif task_prompt == 'More Detailed Caption':
127
  task_prompt = '<MORE_DETAILED_CAPTION>'
128
  results = run_example(task_prompt, image, model_id=model_id)
129
- return results, None
130
  else:
131
  return "", None # Return empty string and None for unknown task prompts
132
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  css = """
134
  #output {
135
  height: 500px;
@@ -157,9 +167,9 @@ with gr.Blocks(css=css) as demo:
157
  text_input = gr.Textbox(label="Text Input (optional)")
158
  submit_btn = gr.Button(value="Submit")
159
  with gr.Column():
160
- output_text = gr.Textbox(label="Output Text")
161
  output_img = gr.Image(label="Output Image")
162
 
163
  submit_btn.click(process_image, [input_img, task_prompt, text_input, model_selector], [output_text, output_img])
164
 
165
- demo.launch(debug=True)
 
122
  if task_prompt == 'Product Caption':
123
  task_prompt = '<PC>'
124
  results = run_example(task_prompt, image, model_id=model_id)
 
125
  elif task_prompt == 'More Detailed Caption':
126
  task_prompt = '<MORE_DETAILED_CAPTION>'
127
  results = run_example(task_prompt, image, model_id=model_id)
 
128
  else:
129
  return "", None # Return empty string and None for unknown task prompts
130
 
131
+ # Remove the key and get the text value
132
+ if results and task_prompt in results:
133
+ output_text = results[task_prompt]
134
+ else:
135
+ output_text = ""
136
+
137
+ # Convert newline characters to HTML line breaks
138
+ output_text = output_text.replace("\n\n", "<br><br>").replace("\n", "<br>")
139
+
140
+ return output_text, None
141
+
142
+
143
  css = """
144
  #output {
145
  height: 500px;
 
167
  text_input = gr.Textbox(label="Text Input (optional)")
168
  submit_btn = gr.Button(value="Submit")
169
  with gr.Column():
170
+ output_text = gr.HTML(label="Output Text")
171
  output_img = gr.Image(label="Output Image")
172
 
173
  submit_btn.click(process_image, [input_img, task_prompt, text_input, model_selector], [output_text, output_img])
174
 
175
+ demo.launch(debug=True)