malvika2003 commited on
Commit
61827fd
1 Parent(s): 2574e89

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -12
app.py CHANGED
@@ -1,19 +1,22 @@
1
- from flask import Flask, request, render_template
 
 
2
 
3
- app = Flask(__name__)
 
4
 
5
- @app.route('/')
6
- def index():
7
- return render_template('index.html')
8
 
9
- @app.route('/predict', methods=['POST'])
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 render_template('index.html', output=output_text)
 
 
 
 
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