Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,9 +3,8 @@ from pydantic import BaseModel
|
|
| 3 |
from fastapi.responses import JSONResponse
|
| 4 |
from transformers import pipeline
|
| 5 |
|
| 6 |
-
# Load
|
| 7 |
-
|
| 8 |
-
pipe = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.1", max_new_tokens=100)
|
| 9 |
|
| 10 |
app = FastAPI()
|
| 11 |
|
|
@@ -14,10 +13,9 @@ class LaTeXRequest(BaseModel):
|
|
| 14 |
|
| 15 |
@app.post("/fix")
|
| 16 |
async def fix_latex(data: LaTeXRequest):
|
| 17 |
-
prompt = f"Fix this malformed LaTeX expression so it's valid
|
| 18 |
try:
|
| 19 |
-
result = pipe(prompt
|
| 20 |
-
|
| 21 |
-
return JSONResponse(content={"fixed_latex": fixed})
|
| 22 |
except Exception as e:
|
| 23 |
return JSONResponse(content={"error": str(e)}, status_code=500)
|
|
|
|
| 3 |
from fastapi.responses import JSONResponse
|
| 4 |
from transformers import pipeline
|
| 5 |
|
| 6 |
+
# Load a small, CPU-friendly instruction-following model
|
| 7 |
+
pipe = pipeline("text2text-generation", model="google/flan-t5-small", max_new_tokens=100)
|
|
|
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
|
|
|
|
| 13 |
|
| 14 |
@app.post("/fix")
|
| 15 |
async def fix_latex(data: LaTeXRequest):
|
| 16 |
+
prompt = f"Fix this malformed LaTeX expression so it's valid:\n{data.latex}"
|
| 17 |
try:
|
| 18 |
+
result = pipe(prompt)[0]["generated_text"]
|
| 19 |
+
return JSONResponse(content={"fixed_latex": result.strip()})
|
|
|
|
| 20 |
except Exception as e:
|
| 21 |
return JSONResponse(content={"error": str(e)}, status_code=500)
|