Spaces:
Sleeping
Sleeping
Download app.py from ed29/ds_model_api: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/ed29/ds_model_api/resolve/main/app.py
- Command line
-
hf download hf://spaces/ed29/ds_model_api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ed29/ds_model_api/resolve/main/app.py
1.1 kB
| import os | |
| from flask import Flask, request, jsonify | |
| from huggingface_hub import InferenceClient | |
| API_KEY = os.getenv('HF_TOKEN') | |
| # Inicializar cliente de Hugging Face | |
| client = InferenceClient( | |
| provider="together", | |
| api_key= API_KEY | |
| ) | |
| # Inicializar aplicación Flask | |
| app = Flask(__name__) | |
| def chat(): | |
| try: | |
| # Obtener el mensaje enviado en la solicitud | |
| data = request.get_json() | |
| messages = data.get('messages', []) | |
| if not messages: | |
| return jsonify({"error": "Messages field is required."}), 400 | |
| # Realizar la llamada al modelo | |
| completion = client.chat.completions.create( | |
| model="deepseek-ai/DeepSeek-R1", | |
| messages=messages, | |
| max_tokens=500 | |
| ) | |
| # Devolver la respuesta del modelo | |
| response_message = completion.choices[0].message.content | |
| return jsonify({"response": response_message}) | |
| except Exception as e: | |
| return jsonify({"error": str(e)}), 500 | |
| #if __name__ == '__main__': | |
| # app.run(host='0.0.0.0', port=5000) |