Nitin00043 commited on
Commit
4a01533
·
verified ·
1 Parent(s): f9e2ef5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -2,14 +2,17 @@ from transformers import Pix2StructForConditionalGeneration, Pix2StructProcessor
2
  import gradio as gr
3
  from PIL import Image
4
 
 
 
 
 
5
  # Load the pre-trained Pix2Struct model and processor
6
- model_name = "google/pix2struct-mathqa-base"
7
  model = Pix2StructForConditionalGeneration.from_pretrained(model_name)
8
  processor = Pix2StructProcessor.from_pretrained(model_name)
9
 
10
  # Function to solve handwritten math problems
11
  def solve_math_problem(image):
12
- # Preprocess the image
13
  inputs = processor(images=image, text="Solve the math problem:", return_tensors="pt")
14
 
15
  # Generate the solution
@@ -25,14 +28,13 @@ demo = gr.Interface(
25
  inputs=gr.Image(type="pil", label="Upload Handwritten Math Problem"),
26
  outputs=gr.Textbox(label="Solution"),
27
  title="Handwritten Math Problem Solver",
28
- description="Upload an image of a handwritten math problem, and the model will solve it.",
29
  examples=[
30
- ["example1.jpg"], # Add example images
31
  ["example2.jpg"]
32
  ],
33
  theme="soft"
34
  )
35
 
36
- # Launch the app
37
  if __name__ == "__main__":
38
- demo.launch()
 
2
  import gradio as gr
3
  from PIL import Image
4
 
5
+ # Use a valid model identifier.
6
+ # Replace "google/matcha-base" with your checkpoint if you have one.
7
+ model_name = "google/matcha-base"
8
+
9
  # Load the pre-trained Pix2Struct model and processor
 
10
  model = Pix2StructForConditionalGeneration.from_pretrained(model_name)
11
  processor = Pix2StructProcessor.from_pretrained(model_name)
12
 
13
  # Function to solve handwritten math problems
14
  def solve_math_problem(image):
15
+ # Preprocess the image: here we render a prompt asking the model to solve the problem.
16
  inputs = processor(images=image, text="Solve the math problem:", return_tensors="pt")
17
 
18
  # Generate the solution
 
28
  inputs=gr.Image(type="pil", label="Upload Handwritten Math Problem"),
29
  outputs=gr.Textbox(label="Solution"),
30
  title="Handwritten Math Problem Solver",
31
+ description="Upload an image of a handwritten math problem, and the model will attempt to solve it.",
32
  examples=[
33
+ ["example1.jpg"], # Add example images if available
34
  ["example2.jpg"]
35
  ],
36
  theme="soft"
37
  )
38
 
 
39
  if __name__ == "__main__":
40
+ demo.launch()