Download app.py from dayday98/cset: direct link, hf CLI and curl.
- Browser
- Download file 1.9 kB
-
https://huggingface.co/spaces/dayday98/cset/resolve/main/app.py
- Command line
-
hf download hf://spaces/dayday98/cset/app.py
-
curl -L -o app.py https://huggingface.co/spaces/dayday98/cset/resolve/main/app.py
1.9 kB
| from flask import Flask, request, jsonify | |
| from flask_cors import CORS | |
| import requests | |
| import os | |
| app = Flask(__name__) | |
| CORS(app) | |
| def chat(): | |
| try: | |
| data = request.json | |
| token = data.get('token') | |
| user_input = data.get('input') | |
| if not token or not user_input: | |
| return jsonify({"error": "Hiányzó token vagy input"}), 400 | |
| headers = { | |
| 'Authorization': f'Bearer {token}' | |
| } | |
| payload = { | |
| 'inputs': user_input, | |
| 'parameters': { | |
| 'max_new_tokens': 500, | |
| 'temperature': 0.7, | |
| 'return_full_text': False | |
| }, | |
| 'options': { | |
| 'wait_for_model': True | |
| } | |
| } | |
| # Eredeti inference API | |
| response = requests.post( | |
| HF_API_URL = "https://router.huggingface.co/models/dphn/Dolphin3.0-Mistral-24B" | |
| json=payload, | |
| headers=headers, | |
| timeout=90 | |
| ) | |
| print(f"Status: {response.status_code}") | |
| print(f"Response: {response.text[:500]}") | |
| if response.status_code == 503: | |
| return jsonify({"error": "A modell még töltődik. Próbáld 30 másodperc múlva."}), 503 | |
| if response.status_code != 200: | |
| return jsonify({ | |
| "error": f"API hiba ({response.status_code})", | |
| "message": response.text[:300] | |
| }), response.status_code | |
| result = response.json() | |
| return jsonify(result) | |
| except Exception as e: | |
| return jsonify({"error": str(e)}), 500 | |
| def home(): | |
| return "🐬 Dolphin Chat API működik! ✅" | |
| if __name__ == '__main__': | |
| port = int(os.environ.get("PORT", 7860)) | |
| app.run(host='0.0.0.0', port=port) |