Download app.py from DIVYA18/ai-agent: direct link, hf CLI and curl.
- Browser
- Download file 833 Bytes
-
https://huggingface.co/spaces/DIVYA18/ai-agent/resolve/main/app.py
- Command line
-
hf download hf://spaces/DIVYA18/ai-agent/app.py
-
curl -L -o app.py https://huggingface.co/spaces/DIVYA18/ai-agent/resolve/main/app.py
833 Bytes
| import os | |
| import google.generativeai as genai | |
| from dotenv import load_dotenv | |
| from flask import Flask, request, jsonify | |
| # Load API Key from .env | |
| load_dotenv() | |
| api_key = os.getenv("AIzaSyAsxYk-QPLXByizAy9ndDiT0vxRhwWAiWw") | |
| # Configure Gemini AI | |
| genai.configure(api_key=api_key) | |
| model = genai.GenerativeModel("gemini-pro") | |
| # Flask App | |
| app = Flask(__name__) | |
| def chat(): | |
| data = request.json | |
| user_input = data.get("message", "") | |
| if not user_input: | |
| return jsonify({"error": "Message is required"}), 400 | |
| try: | |
| response = model.generate_content(user_input) | |
| bot_reply = response.text | |
| return jsonify({"reply": bot_reply}) | |
| except Exception as e: | |
| return jsonify({"error": str(e)}), 500 | |
| if __name__ == "__main__": | |
| app.run(debug=True) | |