Spaces:
Paused
Paused
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() | |
def greet_json(): | |
return {"Hello": "World!"} | |
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 | |
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"] | |
def sentimentAnalysis_func(input:User_input): | |
res= sentimentAnalysis(input.sentence) | |
return res | |
def getReply_func(input:User_input): | |
res= customerConverstaion(input.sentence) | |
return res | |
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) | |