Spaces:
Paused
Paused
File size: 2,183 Bytes
456d207 703e5e6 226a40e c6f40e8 703e5e6 226a40e 703e5e6 226a40e 456d207 703e5e6 456d207 703e5e6 4baab8b 703e5e6 4ac374e 226a40e 4baab8b 226a40e c6f40e8 4baab8b c6f40e8 4ac374e c6f40e8 703e5e6 |
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 |
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
# def query(API_URL, headers, payload):
# response = requests.post(API_URL, headers=headers, json=payload)
# print(response)
# return response
@app.post("/HFAPI")
def HF_API():
# API_TOKEN=""
# API_URL = "https://api-inference.huggingface.co/models/openai-community/gpt2"
# headers = {"Authorization": f"Bearer {API_TOKEN}"}
# data = query(API_URL,headers, {
# "inputs": "Can you please let us know more details about your ",
# })
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
# Initialize API client
api = HfApi()
# Replace these with your values
repo_id = 'DSU-FDP/Sample-API'
token = ''
# Authenticate
api.pause_space(repo_id=repo_id)
# List all Spaces (not pausing, just showing how to interact)
spaces = api.list_spaces()
print(spaces)
# Example action: delete a space (be cautious with this!)
# api.delete_repo(repo_id, token=token)
|