edge-worker-2 / app.py
AEUPH's picture
Upload folder using huggingface_hub
2a0440f verified
Raw
History Blame Contribute Delete
748 Bytes
from flask import Flask, request, jsonify
import os
app = Flask(__name__)
# A simple way to get a unique ID for each worker
# In a real scenario, this would be more robust.
worker_id = os.environ.get("SPACE_ID", "unknown")
@app.route('/')
def hello_world():
return f'Hello, I am worker {worker_id}!'
@app.route('/execute', methods=['POST'])
def execute_task():
task_data = request.json
if not task_data or 'task_data' not in task_data:
return jsonify({"error": "Invalid task data"}), 400
# "Process" the data
result = f"Hello from worker {worker_id}! I processed your data: {task_data['task_data']}"
return jsonify({"result": result})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7860)