sagar007 commited on
Commit
ae24526
1 Parent(s): 63b02f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -5,6 +5,7 @@ import requests
5
  from transformers import AutoModelForCausalLM, AutoProcessor
6
  import torch
7
  import subprocess
 
8
 
9
  # Install flash-attn
10
  subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
@@ -51,6 +52,12 @@ def solve_math_problem(image):
51
  model.to('cpu')
52
  return response
53
 
 
 
 
 
 
 
54
  # Custom CSS
55
  custom_css = """
56
  <style>
@@ -221,6 +228,7 @@ custom_html = """
221
  </div>
222
  """
223
 
 
224
  # Create the Gradio interface
225
  with gr.Blocks(css=custom_css) as iface:
226
  gr.HTML(custom_html)
@@ -235,12 +243,12 @@ with gr.Blocks(css=custom_css) as iface:
235
 
236
  gr.Examples(
237
  examples=[
238
- ["example_math_problem1.jpg"],
239
- ["example_math_problem2.jpg"]
240
  ],
241
  inputs=input_image,
242
  outputs=output_text,
243
- fn=solve_math_problem,
244
  cache_examples=True,
245
  )
246
 
 
5
  from transformers import AutoModelForCausalLM, AutoProcessor
6
  import torch
7
  import subprocess
8
+ from io import BytesIO
9
 
10
  # Install flash-attn
11
  subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
 
52
  model.to('cpu')
53
  return response
54
 
55
+ # Function to load image from URL
56
+ def load_image_from_url(url):
57
+ response = requests.get(url)
58
+ img = Image.open(BytesIO(response.content))
59
+ return img
60
+
61
  # Custom CSS
62
  custom_css = """
63
  <style>
 
228
  </div>
229
  """
230
 
231
+
232
  # Create the Gradio interface
233
  with gr.Blocks(css=custom_css) as iface:
234
  gr.HTML(custom_html)
 
243
 
244
  gr.Examples(
245
  examples=[
246
+ "https://i.imgur.com/2Gwd3bN.jpg", # Replace with actual URLs of math problem images
247
+ "https://i.imgur.com/wPw5YtB.jpg"
248
  ],
249
  inputs=input_image,
250
  outputs=output_text,
251
+ fn=lambda url: solve_math_problem(load_image_from_url(url)),
252
  cache_examples=True,
253
  )
254