|
from fastapi import FastAPI |
|
from pydantic import BaseModel |
|
from calculator import calculate |
|
from sentimentAnalysis import sentimentAnalysis |
|
from customerSupport import customerConverstaion |
|
|
|
|
|
class User_input(BaseModel): |
|
sentence:str |
|
operation:str |
|
x:float |
|
y:float |
|
|
|
|
|
|
|
app = FastAPI() |
|
|
|
@app.get("/hello") |
|
def greet_json(): |
|
return {"Hello": "World!"} |
|
|
|
|
|
@app.post("/calculate") |
|
def calculate_func(input:User_input): |
|
res= calculate(input.operation, input.x, input.y) |
|
return res |
|
|
|
import requests |
|
|
|
|
|
|
|
|
|
@app.post("/HFAPI") |
|
def HF_API(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
API_URL = "https://api-inference.huggingface.co/models/openai-community/gpt2" |
|
headers = {"Authorization": "Bearer ......................q"} |
|
def query(payload): |
|
response = requests.post(API_URL, headers=headers, json=payload) |
|
return response.json() |
|
output = query({ |
|
"inputs": "Can you please let us know more details about India? ", |
|
}) |
|
return output[0]["generated_text"] |
|
|
|
|
|
@app.post("/sentimentAnalysis") |
|
def sentimentAnalysis_func(input:User_input): |
|
res= sentimentAnalysis(input.sentence) |
|
return res |
|
|
|
@app.post("/getReply") |
|
def getReply_func(input:User_input): |
|
res= customerConverstaion(input.sentence) |
|
return res |
|
@app.post("/hf_spaces") |
|
def HF_interact(): |
|
from huggingface_hub import HfApi |
|
|
|
api = HfApi() |
|
|
|
|
|
repo_id = 'DSU-FDP/Sample-API' |
|
token = '' |
|
|
|
|
|
|
|
api.pause_space(repo_id=repo_id) |
|
|
|
|
|
|
|
spaces = api.list_spaces() |
|
print(spaces) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|