ayazfau commited on
Commit
3c82b45
1 Parent(s): 1b6af4a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -23
app.py CHANGED
@@ -1,23 +1,22 @@
1
- from fastapi import FastAPI, Request
2
- from fastapi.responses import HTMLResponse
3
- from fastapi.templating import Jinja2Templates
4
- from transformers import pipeline
5
-
6
- # FastAPI app instance
7
- app = FastAPI()
8
-
9
- # Initializing the text generation pipeline
10
- pipe = pipeline("text2text-generation", model="google/flan-t5-large")
11
-
12
- # Jinja2 template configuration
13
- templates = Jinja2Templates(directory="templates")
14
-
15
- @app.get("/", response_class=HTMLResponse)
16
- async def home(request: Request):
17
- return templates.TemplateResponse("index.html", {"request": request})
18
-
19
- @app.get("/generate")
20
- def generate(text: str):
21
- # Using the pipeline to generate text from given input
22
- output = pipe(text, max_length=50) # Adjust max_length as needed
23
- return {"output": output[0]['generated_text']}
 
1
+ from fastapi import FastAPI, Request
2
+ from fastapi.responses import HTMLResponse
3
+ from fastapi.templating import Jinja2Templates
4
+ from transformers import pipeline
5
+
6
+ # FastAPI app instance
7
+ app = FastAPI()
8
+
9
+ # Initializing the text generation pipeline
10
+ pipe = pipeline("text2text-generation", model="facebook/m2m100_1.2B")
11
+ # Jinja2 template configuration
12
+ templates = Jinja2Templates(directory="templates")
13
+
14
+ @app.get("/", response_class=HTMLResponse)
15
+ async def home(request: Request):
16
+ return templates.TemplateResponse("index.html", {"request": request})
17
+
18
+ @app.get("/generate")
19
+ def generate(text: str):
20
+ # Using the pipeline to generate text from given input
21
+ output = pipe(text, max_length=50) # Adjust max_length as needed
22
+ return {"output": output[0]['generated_text']}