MasteredUltraInstinct commited on
Commit
b78a42b
·
verified ·
1 Parent(s): ee9df95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -7
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 an instruction-tuned model for generation
7
- # This model must be supported on CPU; you can change it if needed
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 and simple:\n```{data.latex}```\nFixed:"
18
  try:
19
- result = pipe(prompt, do_sample=False)[0]["generated_text"]
20
- fixed = result.split("Fixed:")[-1].strip("` \n")
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)