Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,40 @@
|
|
| 1 |
from fastapi import FastAPI
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
app = FastAPI()
|
| 6 |
|
| 7 |
-
# Initialize the text generation
|
| 8 |
pipe = pipeline("text2text-generation", model="google/flan-t5-small")
|
| 9 |
|
| 10 |
@app.get("/")
|
| 11 |
def home():
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
@app.get("/generate")
|
| 15 |
-
def generate(text:str):
|
| 16 |
-
#
|
| 17 |
output = pipe(text)
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
return {"output":output[0]['generated_text']}
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
+
from fastapi.responses import HTMLResponse
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
+
# Create a new FastAPI app instance
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
+
# Initialize the text generation pipeline
|
| 9 |
pipe = pipeline("text2text-generation", model="google/flan-t5-small")
|
| 10 |
|
| 11 |
@app.get("/")
|
| 12 |
def home():
|
| 13 |
+
html_content = """
|
| 14 |
+
<!DOCTYPE html>
|
| 15 |
+
<html lang="en">
|
| 16 |
+
<head>
|
| 17 |
+
<meta charset="UTF-8">
|
| 18 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 19 |
+
<title>Text to Text Generation</title>
|
| 20 |
+
</head>
|
| 21 |
+
<body>
|
| 22 |
+
<h1>Welcome to Text to Text Generation</h1>
|
| 23 |
+
<iframe
|
| 24 |
+
src="https://rohitjakkam-text2text-using-docker.hf.space"
|
| 25 |
+
frameborder="0"
|
| 26 |
+
width="850"
|
| 27 |
+
height="450"
|
| 28 |
+
></iframe>
|
| 29 |
+
</body>
|
| 30 |
+
</html>
|
| 31 |
+
"""
|
| 32 |
+
return HTMLResponse(content=html_content)
|
| 33 |
|
| 34 |
@app.get("/generate")
|
| 35 |
+
def generate(text: str):
|
| 36 |
+
# Use pipeline to generate text from given text as input parameter
|
| 37 |
output = pipe(text)
|
| 38 |
|
| 39 |
+
# Return the generated text in JSON response
|
| 40 |
+
return {"output": output[0]['generated_text']}
|