MasteredUltraInstinct commited on
Commit
ab2bf21
Β·
verified Β·
1 Parent(s): c6ab1d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -12
app.py CHANGED
@@ -2,12 +2,15 @@ import gradio as gr
2
  import matplotlib
3
  matplotlib.use('Agg') # Set Agg backend to avoid Qt issues
4
  import matplotlib.pyplot as plt
 
 
 
5
 
6
- # βœ… LLM microservice integration
7
  import requests
8
- from llm_utils import build_prompt # Already in your repo
9
 
10
- EXPLAIN_API_URL = "http://<your-colab-url>/explain" # πŸ” Replace this with your real URL
11
 
12
  def explain_with_llm(latex_str):
13
  if not latex_str.strip():
@@ -22,15 +25,27 @@ def explain_with_llm(latex_str):
22
  except Exception as e:
23
  return f"❌ Exception: {e}"
24
 
25
- # Import UI tabs
26
- from polynomial import polynomial_tab
27
- from linear import linear_tab
28
- from image import image_tab
29
-
30
  with gr.Blocks(title="Polynomial and Linear System Solver") as demo:
31
- poly_components = polynomial_tab(explain_with_llm) # βœ… Pass function
32
- linear_components = linear_tab(explain_with_llm) # βœ… Pass function
33
- image_components = image_tab(explain_with_llm) # βœ… Pass function
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  if __name__ == "__main__":
36
- demo.launch()
 
2
  import matplotlib
3
  matplotlib.use('Agg') # Set Agg backend to avoid Qt issues
4
  import matplotlib.pyplot as plt
5
+ from polynomial import polynomial_tab
6
+ from linear import linear_tab
7
+ from image import image_tab
8
 
9
+ # βœ… LLM imports (added)
10
  import requests
11
+ from llm_utils import build_prompt
12
 
13
+ EXPLAIN_API_URL = "http://<your-colab-url>/explain" # πŸ” Replace with your actual Colab endpoint
14
 
15
  def explain_with_llm(latex_str):
16
  if not latex_str.strip():
 
25
  except Exception as e:
26
  return f"❌ Exception: {e}"
27
 
 
 
 
 
 
28
  with gr.Blocks(title="Polynomial and Linear System Solver") as demo:
29
+ # Create all tabs
30
+ poly_components = polynomial_tab()
31
+ linear_components = linear_tab()
32
+ image_components = image_tab()
33
+
34
+ # βœ… Attach LLM buttons and outputs (added)
35
+ with gr.Tab("Polynomial Solver"):
36
+ llm_button_poly = gr.Button("Explain with LLM")
37
+ llm_output_poly = gr.Textbox(label="LLM Explanation", lines=4)
38
+ llm_button_poly.click(fn=explain_with_llm, inputs=poly_components[0], outputs=llm_output_poly)
39
+
40
+ with gr.Tab("Linear System Solver"):
41
+ llm_button_lin = gr.Button("Explain with LLM")
42
+ llm_output_lin = gr.Textbox(label="LLM Explanation", lines=4)
43
+ llm_button_lin.click(fn=explain_with_llm, inputs=linear_components[0], outputs=llm_output_lin)
44
+
45
+ with gr.Tab("Image Upload Solver"):
46
+ llm_button_img = gr.Button("Explain with LLM")
47
+ llm_output_img = gr.Textbox(label="LLM Explanation", lines=4)
48
+ llm_button_img.click(fn=explain_with_llm, inputs=image_components[1], outputs=llm_output_img)
49
 
50
  if __name__ == "__main__":
51
+ demo.launch() # Removed server_port=7860 to allow automatic port selection