astro21 commited on
Commit
59d9679
·
1 Parent(s): feec7ea

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +15 -16
main.py CHANGED
@@ -1,21 +1,20 @@
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)
 
1
+ from fastapi import FastAPI
2
  from gradio_client import Client
 
3
 
4
+ app = FastAPI()
 
5
 
6
+ # Define a route for the prediction using FastAPI
7
+ @app.post("/predict")
8
+ async def predict(text: str):
9
+ # Replace this URL with the actual API endpoint URL
10
+ api_endpoint_url = "https://astro21-test-2.hf.space/--replicas/x5m8s/"
11
 
12
+ # Use the Gradio client to make the prediction request
13
+ client = Client(api_endpoint_url)
14
+ result = client.predict(
15
+ text,
16
+ api_name="/predict"
17
+ )
18
 
19
+ # Return the result as a response
20
+ return {"result": result}