File size: 937 Bytes
38120aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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}