Maha / app.py
Nexavo's picture
Update app.py
9ddf02a verified
Raw History Blame Contribute Delete
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")
@app.route("/chat", methods=["POST"])
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)