Spaces:
Running
Running
Download server.py from Faheemkabeer/Gesture-Drop: direct link, hf CLI and curl.
- Browser
- Download file 1.71 kB
-
https://huggingface.co/spaces/Faheemkabeer/Gesture-Drop/resolve/main/server.py
- Command line
-
hf download hf://spaces/Faheemkabeer/Gesture-Drop/server.py
-
curl -L -o server.py https://huggingface.co/spaces/Faheemkabeer/Gesture-Drop/resolve/main/server.py
1.71 kB
| from flask import Flask, request, jsonify, render_template, redirect, url_for | |
| from werkzeug.utils import secure_filename | |
| import os | |
| app = Flask(__name__) | |
| UPLOAD_FOLDER = os.path.join('static', 'uploads') | |
| app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER | |
| text_data = "" | |
| image_filename = "" | |
| def index(): | |
| return render_template('mobile_view.html') | |
| def upload(): | |
| global image_filename | |
| if request.method == 'POST': | |
| if 'file' not in request.files: | |
| return "No file part" | |
| file = request.files['file'] | |
| if file.filename == '': | |
| return "No selected file" | |
| filename = secure_filename(file.filename) | |
| file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) | |
| image_filename = filename | |
| return f"✅ Uploaded: {filename}<br><br><a href='/'>🔗 View on phone</a>" | |
| return ''' | |
| <h2>📤 Upload an Image to Send to Phone</h2> | |
| <form method="post" enctype="multipart/form-data"> | |
| <input type="file" name="file"> | |
| <input type="submit" value="Upload"> | |
| </form> | |
| ''' | |
| def save(): | |
| global text_data | |
| data = request.get_json() | |
| text_data = data.get("text", "") | |
| print(f"[✅] Text Saved: {text_data}") | |
| return jsonify({"status": "success"}) | |
| def get(): | |
| return jsonify({ | |
| "text": text_data, | |
| "image": image_filename | |
| }) | |
| if __name__ == '__main__': | |
| if not os.path.exists(UPLOAD_FOLDER): | |
| os.makedirs(UPLOAD_FOLDER) | |
| app.run(host='0.0.0.0', port=5000) | |