Spaces:
Sleeping
Sleeping
from fastapi import FastAPI | |
from gradio_client import Client | |
from fastapi.middleware.cors import CORSMiddleware | |
app = FastAPI() | |
# Add CORS middleware to allow requests from any origin (for development) | |
app.add_middleware( | |
CORSMiddleware, | |
allow_origins=["*"], | |
allow_methods=["*"], | |
allow_headers=["*"], | |
) | |
# Define a route for the prediction using FastAPI | |
@app.post("/predict") | |
async def predict(text: str): | |
client = Client("https://randomshit11-randomshit11-fin-bert-1st-shit.hf.space/--replicas/pnvrn/") | |
result = client.predict( | |
"shorten", # str in 'Mode' Radio component | |
text, # str in 'text' Textbox component | |
5, # int | float (numeric value between 5 and 200) in 'Min length' Slider component | |
128, # int | float (numeric value between 5 and 500) in 'Max length' Slider component | |
api_name="/predict" | |
) | |
print(result) | |
# Return the result as a response | |
return {"result": result} |