Update main.py
Browse files
main.py
CHANGED
@@ -1,25 +1,21 @@
|
|
1 |
-
from
|
2 |
-
from
|
3 |
-
import
|
4 |
|
5 |
-
app =
|
|
|
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.
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
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)
|