Spaces:
Runtime error
Runtime error
malvika2003
commited on
Commit
•
61827fd
1
Parent(s):
2574e89
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,22 @@
|
|
1 |
-
from
|
|
|
|
|
2 |
|
3 |
-
app =
|
|
|
4 |
|
5 |
-
@app.
|
6 |
-
def
|
7 |
-
return
|
8 |
|
9 |
-
@app.
|
10 |
-
def predict():
|
11 |
# Example of processing input
|
12 |
-
input_text = request.form['input_text']
|
13 |
-
# Perform some NLP tasks here (e.g., using transformers library)
|
14 |
output_text = "This is the output based on input: " + input_text
|
15 |
-
return
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
if __name__ == '__main__':
|
18 |
-
app.run(debug=True)
|
19 |
|
|
|
1 |
+
from fastapi import FastAPI, Form, Request
|
2 |
+
from fastapi.responses import HTMLResponse
|
3 |
+
from fastapi.templating import Jinja2Templates
|
4 |
|
5 |
+
app = FastAPI()
|
6 |
+
templates = Jinja2Templates(directory="templates")
|
7 |
|
8 |
+
@app.get("/", response_class=HTMLResponse)
|
9 |
+
async def read_form(request: Request):
|
10 |
+
return templates.TemplateResponse("index.html", {"request": request})
|
11 |
|
12 |
+
@app.post("/predict")
|
13 |
+
async def predict(input_text: str = Form(...)):
|
14 |
# Example of processing input
|
|
|
|
|
15 |
output_text = "This is the output based on input: " + input_text
|
16 |
+
return {"output": output_text}
|
17 |
+
|
18 |
+
if __name__ == "__main__":
|
19 |
+
import uvicorn
|
20 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
21 |
|
|
|
|
|
22 |
|