Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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="
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
output
|
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']}
|
|