Spaces:
Runtime error
Runtime error
AkshayaKeerthi
commited on
Commit
•
921a24e
1
Parent(s):
58fda82
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,26 @@
|
|
1 |
-
|
2 |
-
|
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 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
16 |
|
17 |
-
@app.
|
18 |
-
def
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
return jsonify({'response': "Hello, Hugging Face!"})#response_text
|
23 |
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
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
|