Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,10 +1,26 @@
|
|
| 1 |
-
from flask import Flask
|
|
|
|
| 2 |
|
| 3 |
app = Flask(__name__)
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
@app.route('/')
|
| 6 |
def hello_world():
|
| 7 |
-
return 'Hello, I am
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
if __name__ == '__main__':
|
| 10 |
app.run(host='0.0.0.0', port=7860)
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
+
import os
|
| 3 |
|
| 4 |
app = Flask(__name__)
|
| 5 |
|
| 6 |
+
# A simple way to get a unique ID for each worker
|
| 7 |
+
# In a real scenario, this would be more robust.
|
| 8 |
+
worker_id = os.environ.get("SPACE_ID", "unknown")
|
| 9 |
+
|
| 10 |
@app.route('/')
|
| 11 |
def hello_world():
|
| 12 |
+
return f'Hello, I am worker {worker_id}!'
|
| 13 |
+
|
| 14 |
+
@app.route('/execute', methods=['POST'])
|
| 15 |
+
def execute_task():
|
| 16 |
+
task_data = request.json
|
| 17 |
+
if not task_data or 'task_data' not in task_data:
|
| 18 |
+
return jsonify({"error": "Invalid task data"}), 400
|
| 19 |
+
|
| 20 |
+
# "Process" the data
|
| 21 |
+
result = f"Hello from worker {worker_id}! I processed your data: {task_data['task_data']}"
|
| 22 |
+
|
| 23 |
+
return jsonify({"result": result})
|
| 24 |
|
| 25 |
if __name__ == '__main__':
|
| 26 |
app.run(host='0.0.0.0', port=7860)
|