randomshit11 commited on
Commit
38120aa
1 Parent(s): 79780b1

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +30 -0
main.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from gradio_client import Client
3
+ from fastapi.middleware.cors import CORSMiddleware
4
+
5
+ app = FastAPI()
6
+
7
+ # Add CORS middleware to allow requests from any origin (for development)
8
+ app.add_middleware(
9
+ CORSMiddleware,
10
+ allow_origins=["*"],
11
+ allow_methods=["*"],
12
+ allow_headers=["*"],
13
+ )
14
+
15
+ # Define a route for the prediction using FastAPI
16
+ @app.post("/predict")
17
+ async def predict(text: str):
18
+ client = Client("https://randomshit11-randomshit11-fin-bert-1st-shit.hf.space/--replicas/pnvrn/")
19
+ result = client.predict(
20
+ "shorten", # str in 'Mode' Radio component
21
+ text, # str in 'text' Textbox component
22
+ 5, # int | float (numeric value between 5 and 200) in 'Min length' Slider component
23
+ 128, # int | float (numeric value between 5 and 500) in 'Max length' Slider component
24
+ api_name="/predict"
25
+ )
26
+ print(result)
27
+
28
+
29
+ # Return the result as a response
30
+ return {"result": result}