File size: 881 Bytes
3c32f33
 
 
 
 
 
 
 
 
095882d
3c32f33
 
 
095882d
 
 
3c32f33
 
 
 
 
 
 
 
4dc45ab
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
from fastapi import FastAPI, HTTPException
from typing import Dict
import httpx

app = FastAPI()

# Define the Gradio API endpoint
gradio_api_url = "https://astro21-test-2.hf.space/--replicas/x5m8s/"

# Function to summarize a file using the Gradio API
# Function to summarize a file using the Gradio API
async def summarize_file_with_gradio(file_content: str) -> Dict[str, str]:
    try:
        client = GradioClient(gradio_api_url)
        result = await client.predict(file_content, api_name="/predict")
        return {"summary": result[0]}
    except Exception as e:
        return {"error": str(e)}

# Define a route to handle summarization requests
@app.post('/summarize', response_model=Dict[str, str])
async def summarize_text(data: Dict[str, str]):
    file_content = data.get('file_content')
    result = await summarize_file_with_gradio(file_content)
    return result