asdfasdfdsafdsa commited on
Commit
93ac856
·
verified ·
1 Parent(s): b64c0b6

Update to Gradio 5.43.1 with modern Blocks API

Browse files
Files changed (2) hide show
  1. app.py +53 -21
  2. requirements.txt +1 -1
app.py CHANGED
@@ -243,26 +243,58 @@ print("Loading PGPS model...")
243
  model, src_lang, tgt_lang, cfg = load_model()
244
  print("Model loaded successfully!")
245
 
246
- # Create Gradio interface
247
- iface = gr.Interface(
248
- fn=predict,
249
- inputs=[
250
- gr.Image(type="pil", label="Geometry Diagram"),
251
- gr.Textbox(
252
- lines=3,
253
- placeholder="Enter the geometry problem text here...\nExample: Find the angle x if angle ABC is 60 degrees",
254
- label="Problem Text"
255
- )
256
- ],
257
- outputs=gr.Textbox(label="Solution", lines=5),
258
- title="PGPS: Neural Geometric Problem Solver",
259
- description="Upload a geometry diagram and provide the problem text to get a solution.",
260
- examples=[
261
- [None, "Find the value of angle x if angle ABC is 60 degrees and angle BCD is 90 degrees"],
262
- [None, "Calculate the area of triangle ABC if AB = 5, BC = 7, and angle B = 60 degrees"]
263
- ],
264
- theme="default"
265
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
 
267
  if __name__ == "__main__":
268
- iface.launch()
 
243
  model, src_lang, tgt_lang, cfg = load_model()
244
  print("Model loaded successfully!")
245
 
246
+ # Create Gradio interface with v5+ compatible syntax
247
+ with gr.Blocks(title="PGPS: Neural Geometric Problem Solver") as demo:
248
+ gr.Markdown("# PGPS: Neural Geometric Problem Solver")
249
+ gr.Markdown("Upload a geometry diagram and provide the problem text to get a solution.")
250
+
251
+ with gr.Row():
252
+ with gr.Column():
253
+ image_input = gr.Image(
254
+ type="pil",
255
+ label="Geometry Diagram",
256
+ height=300
257
+ )
258
+ text_input = gr.Textbox(
259
+ lines=3,
260
+ placeholder="Enter the geometry problem text here...\nExample: Find the angle x if angle ABC is 60 degrees",
261
+ label="Problem Text"
262
+ )
263
+ submit_btn = gr.Button("Solve", variant="primary")
264
+
265
+ with gr.Column():
266
+ output = gr.Textbox(
267
+ label="Solution",
268
+ lines=10,
269
+ max_lines=20
270
+ )
271
+
272
+ # Examples
273
+ gr.Examples(
274
+ examples=[
275
+ [None, "Find the value of angle x if angle ABC is 60 degrees and angle BCD is 90 degrees"],
276
+ [None, "Calculate the area of triangle ABC if AB = 5, BC = 7, and angle B = 60 degrees"],
277
+ [None, "In triangle PQR, if angle P = 45 degrees and angle Q = 60 degrees, find angle R"],
278
+ [None, "Find the perimeter of a rectangle with length 8 and width 5"]
279
+ ],
280
+ inputs=[image_input, text_input],
281
+ outputs=output,
282
+ fn=predict,
283
+ cache_examples=False
284
+ )
285
+
286
+ # Event handlers
287
+ submit_btn.click(
288
+ fn=predict,
289
+ inputs=[image_input, text_input],
290
+ outputs=output
291
+ )
292
+
293
+ text_input.submit(
294
+ fn=predict,
295
+ inputs=[image_input, text_input],
296
+ outputs=output
297
+ )
298
 
299
  if __name__ == "__main__":
300
+ demo.launch()
requirements.txt CHANGED
@@ -1,6 +1,6 @@
1
  torch>=2.0.0
2
  torchvision>=0.15.0
3
- gradio==4.16.0
4
  Pillow>=9.0.0
5
  numpy>=1.19.0
6
  antlr4-python3-runtime==4.10
 
1
  torch>=2.0.0
2
  torchvision>=0.15.0
3
+ gradio>=5.0.0
4
  Pillow>=9.0.0
5
  numpy>=1.19.0
6
  antlr4-python3-runtime==4.10