Spaces:
Runtime error
Runtime error
Create llm_interface.py
Browse files- llm_interface.py +18 -0
llm_interface.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# llm_interface.py
|
| 2 |
+
import requests
|
| 3 |
+
from llm_utils import build_prompt
|
| 4 |
+
|
| 5 |
+
EXPLAIN_API_URL = "http://<your-colab-url>/explain" # β Replace this with your actual backend URL
|
| 6 |
+
|
| 7 |
+
def explain_with_llm(latex_str):
|
| 8 |
+
if not latex_str.strip():
|
| 9 |
+
return "β οΈ No LaTeX input provided."
|
| 10 |
+
prompt = build_prompt(latex_str)
|
| 11 |
+
try:
|
| 12 |
+
response = requests.post(EXPLAIN_API_URL, json={"latex": prompt})
|
| 13 |
+
if response.status_code == 200:
|
| 14 |
+
return response.json().get("explanation", "No explanation returned.")
|
| 15 |
+
else:
|
| 16 |
+
return f"β Error: {response.status_code} - {response.text}"
|
| 17 |
+
except Exception as e:
|
| 18 |
+
return f"β Exception: {e}"
|