AkshayaKeerthi commited on
Commit
921a24e
1 Parent(s): 58fda82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -18
app.py CHANGED
@@ -1,25 +1,26 @@
1
- # app.py
2
- #from flask import Flask, render_template, request, jsonify
3
-
4
- from fastapi import FastAPI
5
  from fastapi.staticfiles import StaticFiles
6
- from fastapi.responses import FileResponse
7
-
8
  from transformers import pipeline
9
 
10
  app = FastAPI()
11
- #model = pipeline('question-answering', model='bert-large-uncased-whole-word-masking-finetuned-squad', revision='main')
12
 
13
- @app.route('/')
14
- def home():
15
- return render_template('index.html')
 
 
16
 
17
- @app.route('/predict', methods=['POST'])
18
- def predict():
19
- user_input = request.json.get('message')
20
- #result = model(user_input)
21
- #response_text = result[0]['generated_text']
22
- return jsonify({'response': "Hello, Hugging Face!"})#response_text
23
 
24
- #if __name__ == '__main__':
25
- # app.run(host='0.0.0.0', port=5000)
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Request
2
+ from fastapi.responses import HTMLResponse, JSONResponse
 
 
3
  from fastapi.staticfiles import StaticFiles
 
 
4
  from transformers import pipeline
5
 
6
  app = FastAPI()
 
7
 
8
+ # Uncomment and set up the model if needed
9
+ # model = pipeline('question-answering', model='bert-large-uncased-whole-word-masking-finetuned-squad', revision='main')
10
+
11
+ # Serve static files (e.g., CSS, JS, images)
12
+ app.mount("/static", StaticFiles(directory="static"), name="static")
13
 
14
+ @app.get("/", response_class=HTMLResponse)
15
+ async def home(request: Request):
16
+ with open("templates/index.html") as f:
17
+ html_content = f.read()
18
+ return HTMLResponse(content=html_content)
 
19
 
20
+ @app.post("/predict", response_class=JSONResponse)
21
+ async def predict(request: Request):
22
+ data = await request.json()
23
+ user_input = data.get('message')
24
+ # result = model(user_input)
25
+ # response_text = result[0]['generated_text']
26
+ return JSONResponse(content={'response': "Hello, Hugging Face!"}) # response_text