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

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +13 -17
main.py CHANGED
@@ -1,25 +1,21 @@
1
- from fastapi import FastAPI, HTTPException
2
- from typing import Dict
3
- import httpx
4
 
5
- app = FastAPI()
 
6
 
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
 
20
  # Define a route to handle summarization requests
21
- @app.post('/summarize', response_model=Dict[str, str])
22
- async def summarize_text(data: Dict[str, str]):
23
- file_content = data.get('file_content')
24
- result = await summarize_file_with_gradio(file_content)
25
- return result
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ from gradio_client import Client
3
+ from flask_cors import CORS, cross_origin
4
 
5
+ app = Flask(__name__)
6
+ cors = CORS(app)
7
 
8
  # Define the Gradio API endpoint
9
  gradio_api_url = "https://astro21-test-2.hf.space/--replicas/x5m8s/"
10
 
11
  # Function to summarize a file using the Gradio API
 
 
 
 
 
 
 
 
12
 
13
  # Define a route to handle summarization requests
14
+ @app.route('/summarize', methods=['GET' , 'POST'])
15
+ def summarize_text():
16
+ if request.method == 'POST':
17
+ data = request.get_json()
18
+ file_content = data.get('file_content')
19
+ # app.logger.info(file_content)
20
+ result = summarize_file_with_gradio(file_content)
21
+ return jsonify(result)