File size: 799 Bytes
59d9679
feec7ea
e097cb7
3c32f33
59d9679
3c32f33
e097cb7
 
 
 
 
 
 
 
59d9679
 
 
 
6c7afbb
3c32f33
59d9679
 
 
 
 
 
3c32f33
59d9679
 
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):
    # Replace this URL with the actual API endpoint URL
    api_endpoint_url = "https://astro21-test-2.hf.space/--replicas/7592n/"

    # Use the Gradio client to make the prediction request
    client = Client(api_endpoint_url)
    result = client.predict(
        text,
        api_name="/predict"
    )

    # Return the result as a response
    return {"result": result}