astro21 commited on
Commit
095882d
·
1 Parent(s): f29e282

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +4 -8
main.py CHANGED
@@ -7,17 +7,13 @@ app = FastAPI()
7
  # Define the Gradio API endpoint
8
  gradio_api_url = "https://astro21-test-2.hf.space/--replicas/x5m8s/"
9
 
 
10
  # Function to summarize a file using the Gradio API
11
  async def summarize_file_with_gradio(file_content: str) -> Dict[str, str]:
12
  try:
13
- async with httpx.AsyncClient() as client:
14
- response = await client.post(f"{gradio_api_url}/predict", json={"file_content": file_content})
15
- if response.status_code == 200:
16
- result = response.json()
17
- print(result)
18
- return {"summary": result[0]}
19
- else:
20
- return {"error": "Gradio API request failed"}
21
  except Exception as e:
22
  return {"error": str(e)}
23
 
 
7
  # Define the Gradio API endpoint
8
  gradio_api_url = "https://astro21-test-2.hf.space/--replicas/x5m8s/"
9
 
10
+ # Function to summarize a file using the Gradio API
11
  # Function to summarize a file using the Gradio API
12
  async def summarize_file_with_gradio(file_content: str) -> Dict[str, str]:
13
  try:
14
+ client = GradioClient(gradio_api_url)
15
+ result = await client.predict(file_content, api_name="/predict")
16
+ return {"summary": result[0]}
 
 
 
 
 
17
  except Exception as e:
18
  return {"error": str(e)}
19