File size: 2,078 Bytes
aa8bde2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
import io
from fastapi import FastAPI, File, UploadFile
from werkzeug.utils import secure_filename
import speech_recognition as sr
import subprocess
import os
import requests
import random
import pandas as pd
from pydub import AudioSegment
from datetime import datetime
from datetime import date
import numpy as np
from sklearn.ensemble import RandomForestRegressor
import shutil
import json
from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
from pydantic import BaseModel
from typing import Annotated

from fastapi import Form

class Query(BaseModel):
    question: str
    context: str
    



model_name = "deepset/roberta-base-squad2"

# a) Get predictions
nlp = pipeline('question-answering', model=model_name, tokenizer=model_name)



# from pyngrok import ngrok, conf
# from datetime import datetime

from fastapi import FastAPI, Request, Depends, UploadFile, File
from fastapi.exceptions import HTTPException
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse

# from config import NGROK_AUTH_TOKEN



# now = datetime.now()


# UPLOAD_FOLDER = '/files'
# ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png',
#                       'jpg', 'jpeg', 'gif', 'ogg', 'mp3', 'wav'}


app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=['*'],
    allow_credentials=True,
    allow_methods=['*'],
    allow_headers=['*'],
)


# cred = credentials.Certificate('key.json')
# app1 = firebase_admin.initialize_app(cred)
# db = firestore.client()
# data_frame = pd.read_csv('data.csv')



@app.on_event("startup")
async def startup_event():
   print("on startup")

   


@app.post("/")
async def get_answer(q: Query ):
      
    
    QA_input = {
        'question': q.question ,
        'context': q.context
    }
    res = nlp(QA_input)
    print(res)
    return res
    return "hello"
    


@app.get("/predict")
def get_prediction(address: str, day: int):
    return predict.get(address, day)