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 , min_length: int , max_length: int ): client = Client("https://randomshit11-randomshit11-fin-bert-1st-shit.hf.space/--replicas/7cc9645sr2l/") result = client.predict( "shorten", # str in 'Mode' Radio component text, # str in 'text' Textbox component min_length, # int | float (numeric value between 5 and 200) in 'Min length' Slider component max_length, # 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}