Spaces:
Build error
Build error
Commit
·
a98aa1a
1
Parent(s):
66abe9b
Update main.py
Browse files
main.py
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 , min_length: int , max_length: int ):
|
| 18 |
+
from gradio_client import Client
|
| 19 |
+
|
| 20 |
+
client = Client("https://randomshit11-randomshit11-fin-bert-1st-shit.hf.space/--replicas/7cc9645sr2l/")
|
| 21 |
+
result = client.predict(
|
| 22 |
+
"shorten", # str in 'Mode' Radio component
|
| 23 |
+
text, # str in 'text' Textbox component
|
| 24 |
+
min_length, # int | float (numeric value between 5 and 200) in 'Min length' Slider component
|
| 25 |
+
max_length, # int | float (numeric value between 5 and 500) in 'Max length' Slider component
|
| 26 |
+
api_name="/predict"
|
| 27 |
+
)
|
| 28 |
+
print(result)
|
| 29 |
+
|
| 30 |
+
# Return the result as a response
|
| 31 |
+
return {"result": result}
|