Spaces:
Sleeping
Sleeping
Download app.py from nutripath/nutripath-ai: direct link, hf CLI and curl.
- Browser
- Download file 1.84 kB
-
https://huggingface.co/spaces/nutripath/nutripath-ai/resolve/main/app.py
- Command line
-
hf download hf://spaces/nutripath/nutripath-ai/app.py
-
curl -L -o app.py https://huggingface.co/spaces/nutripath/nutripath-ai/resolve/main/app.py
1.84 kB
| from flask import Flask, request, jsonify | |
| from flask_cors import CORS | |
| import google.generativeai as genai | |
| import os | |
| app = Flask(__name__) | |
| CORS(app) | |
| genai.configure(api_key=os.environ.get("GEMINI_API_KEY")) | |
| model = genai.GenerativeModel('gemini-2.5-flash-lite') | |
| def health(): | |
| return jsonify({'status': 'ok'}) | |
| def chat(): | |
| try: | |
| data = request.json | |
| message = data.get('message', '') | |
| response = model.generate_content(message) | |
| return jsonify({'reply': response.text}) | |
| except Exception as e: | |
| return jsonify({'error': str(e)}), 500 | |
| def ai_suggestion(): | |
| try: | |
| data = request.json | |
| prompt = data.get('prompt', '') | |
| if not prompt: | |
| return jsonify({'error': 'No prompt provided'}), 400 | |
| response = model.generate_content(prompt) | |
| return jsonify({'reply': response.text}) | |
| except Exception as e: | |
| return jsonify({'error': str(e)}), 500 | |
| def scan_meal(): | |
| try: | |
| data = request.json | |
| prompt = data.get('prompt', '') | |
| image_base64 = data.get('image', '') | |
| if not prompt: | |
| return jsonify({'error': 'No prompt provided'}), 400 | |
| if image_base64: | |
| import base64 | |
| image_data = base64.b64decode(image_base64) | |
| image_part = {'mime_type': 'image/jpeg', 'data': image_data} | |
| response = model.generate_content([prompt, image_part]) | |
| else: | |
| response = model.generate_content(prompt) | |
| return jsonify({'reply': response.text}) | |
| except Exception as e: | |
| return jsonify({'error': str(e)}), 500 | |
| if __name__ == '__main__': | |
| app.run(host='0.0.0.0', port=7860) |