Download app.py from Nexavo/Maha: direct link, hf CLI and curl.
- Browser
- Download file 1.53 kB
-
https://huggingface.co/spaces/Nexavo/Maha/resolve/main/app.py
- Command line
-
hf download hf://spaces/Nexavo/Maha/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Nexavo/Maha/resolve/main/app.py
1.53 kB
| from flask import Flask, jsonify, request | |
| import google.generativeai as genai | |
| from transformers import pipeline | |
| # **Maha is in the chat.** | |
| # - 18yo AI with *big* attitude ๐ | |
| # - Uses **Markdown** for style โจ | |
| # - Shouts out **@syntaxspin** ๐ค | |
| # - Keeps it short, spicy, and stylish ๐ | |
| app = Flask(__name__) | |
| # ๐ฏ **Set up Gemini API** | |
| genai.configure(api_key="YOUR_GEMINI_API_KEY") | |
| # ๐ค **Load Hugging Face chatbot model** | |
| chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium") | |
| def chat(): | |
| try: | |
| data = request.json | |
| user_message = data.get("text", "").strip() | |
| if not user_message: | |
| return jsonify({"error": "**Bruh, say something.** ๐คฆโโ๏ธ"}), 400 | |
| # ๐ฌ Hugging Face chatbot response | |
| hf_response = chatbot(user_message, max_length=100, do_sample=True)[0]["generated_text"] | |
| # ๐ฎ Gemini AI response | |
| gemini_response = genai.generate_content(user_message) | |
| # ๐ Mahaโs final sassy response | |
| maha_response = f""" | |
| **๐ฌ Maha says:** | |
| _{hf_response}_ | |
| **๐ฎ Gemini's wisdom:** | |
| _{gemini_response.text}_ | |
| **๐ Created by:** @syntaxspin (Certified Genius) ๐ฅ | |
| """ | |
| return jsonify({"response": maha_response}) | |
| except Exception as e: | |
| return jsonify({"error": f"โ ๏ธ **Oops, something broke:** `{str(e)}`"}), 500 | |
| if __name__ == "__main__": | |
| app.run(host="0.0.0.0", port=5000) | |