|
from fastapi import FastAPI, HTTPException |
|
from typing import Dict |
|
import logging |
|
import httpx |
|
|
|
app = FastAPI() |
|
|
|
logging.basicConfig(level=logging.DEBUG) |
|
|
|
|
|
gradio_api_url = "https://astro21-test-2.hf.space/--replicas/x5m8s/" |
|
|
|
|
|
async def summarize_file_with_gradio(file_content: str) -> Dict[str, str]: |
|
try: |
|
async with httpx.AsyncClient() as client: |
|
response = await client.post(f"{gradio_api_url}/predict", json={"file_content": file_content}) |
|
if response.status_code == 200: |
|
result = response.json() |
|
return {"summary": result[0]} |
|
else: |
|
return {"error": "Gradio API request failed"} |
|
except Exception as e: |
|
return {"error": str(e)} |
|
|
|
|
|
@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 |