Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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
|
| 7 |
import requests
|
| 8 |
-
from llm_utils import build_prompt
|
| 9 |
|
| 10 |
-
EXPLAIN_API_URL = "http://<your-colab-url>/explain" # π Replace
|
| 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 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|