staghado commited on
Commit
d5a7e96
Β·
verified Β·
1 Parent(s): 111ff5f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -15
app.py CHANGED
@@ -27,7 +27,8 @@ def process_image(image, temperature):
27
  Send image to vLLM endpoint and stream the response.
28
  """
29
  if image is None:
30
- return "Please upload an image first."
 
31
 
32
  # Convert image to base64
33
  b64_image = image_to_base64(image)
@@ -75,12 +76,12 @@ def process_image(image, temperature):
75
  content = delta.get('content', '')
76
  if content:
77
  accumulated_response += content
78
- yield accumulated_response
79
  except json.JSONDecodeError:
80
  continue
81
 
82
  except Exception as e:
83
- yield f"Error: {str(e)}"
84
 
85
 
86
  # Build the Gradio Interface
@@ -98,11 +99,12 @@ with gr.Blocks(title="πŸ“– Image OCR", theme=gr.themes.Soft()) as demo:
98
  )
99
 
100
  with gr.Row():
101
- with gr.Column(scale=1):
102
  image_input = gr.Image(
103
  type="pil",
104
  label="πŸ–ΌοΈ Upload Image",
105
- sources=["upload", "clipboard"]
 
106
  )
107
  temperature = gr.Slider(
108
  minimum=0.1,
@@ -114,23 +116,25 @@ with gr.Blocks(title="πŸ“– Image OCR", theme=gr.themes.Soft()) as demo:
114
  submit_btn = gr.Button("Extract Text", variant="primary")
115
  clear_btn = gr.Button("Clear", variant="secondary")
116
 
117
- with gr.Column(scale=2):
118
  output_text = gr.Markdown(
119
- label="πŸ“„ Extracted Text",
120
- value="<div style='min-height: 400px; padding: 10px; border: 1px solid #e0e0e0; border-radius: 4px; background-color: #f9f9f9;'><em>Extracted text will appear here...</em></div>"
 
121
  )
122
 
123
  with gr.Row():
124
- raw_output = gr.Textbox(
125
- label="Raw Output",
126
- placeholder="Raw text will appear here...",
127
- lines=10,
128
- show_copy_button=True
129
- )
 
130
 
131
  # Event handlers
132
  submit_btn.click(
133
- fn=lambda img, temp: (process_image(img, temp), process_image(img, temp)),
134
  inputs=[image_input, temperature],
135
  outputs=[output_text, raw_output]
136
  )
 
27
  Send image to vLLM endpoint and stream the response.
28
  """
29
  if image is None:
30
+ yield "Please upload an image first.", ""
31
+ return
32
 
33
  # Convert image to base64
34
  b64_image = image_to_base64(image)
 
76
  content = delta.get('content', '')
77
  if content:
78
  accumulated_response += content
79
+ yield accumulated_response, accumulated_response
80
  except json.JSONDecodeError:
81
  continue
82
 
83
  except Exception as e:
84
+ yield f"Error: {str(e)}", f"Error: {str(e)}"
85
 
86
 
87
  # Build the Gradio Interface
 
99
  )
100
 
101
  with gr.Row():
102
+ with gr.Column():
103
  image_input = gr.Image(
104
  type="pil",
105
  label="πŸ–ΌοΈ Upload Image",
106
+ sources=["upload", "clipboard"],
107
+ height=400
108
  )
109
  temperature = gr.Slider(
110
  minimum=0.1,
 
116
  submit_btn = gr.Button("Extract Text", variant="primary")
117
  clear_btn = gr.Button("Clear", variant="secondary")
118
 
119
+ with gr.Column():
120
  output_text = gr.Markdown(
121
+ label="πŸ“„ Extracted Text (Rendered)",
122
+ value="<div style='min-height: 400px; padding: 10px; border: 1px solid #e0e0e0; border-radius: 4px; background-color: #f9f9f9;'><em>Extracted text will appear here...</em></div>",
123
+ height=500
124
  )
125
 
126
  with gr.Row():
127
+ with gr.Column():
128
+ raw_output = gr.Textbox(
129
+ label="Raw Markdown Output",
130
+ placeholder="Raw text will appear here...",
131
+ lines=15,
132
+ show_copy_button=True
133
+ )
134
 
135
  # Event handlers
136
  submit_btn.click(
137
+ fn=process_image,
138
  inputs=[image_input, temperature],
139
  outputs=[output_text, raw_output]
140
  )