MasteredUltraInstinct commited on
Commit
dff2458
·
verified ·
1 Parent(s): f997954

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ 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
+
12
+ class LaTeXRequest(BaseModel):
13
+ latex: str
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)