AI-API / app.py
JJ94's picture
Update app.py
f79962c verified
raw
history blame
1.12 kB
from flask import Flask, request, jsonify, render_template
from llama_cpp import Llama
app = Flask(__name__)
# Load the model
print("πŸ”„ Loading model... (this may take a while)")
llm = Llama.from_pretrained(
repo_id="bartowski/google_gemma-3-1b-it-GGUF",
filename="google_gemma-3-1b-it-IQ4_XS.gguf",
)
print("βœ… Model loaded!")
@app.route("/")
def home():
print("πŸ“’ Serving index.html")
return render_template("index.html")
@app.route("/chat", methods=["POST"])
def chat():
user_input = request.json.get("message", "")
print(f"πŸ’¬ Received message: {user_input}")
if not user_input:
print("⚠️ Empty input received!")
return jsonify({"error": "Empty input"}), 400
response = llm.create_chat_completion(
messages=[{"role": "user", "content": user_input}]
)
bot_reply = response["choices"][0]["message"]["content"]
print(f"πŸ€– Bot response: {bot_reply}")
return jsonify({"response": bot_reply})
if __name__ == "__main__":
print("πŸš€ Starting Flask app on port 7860")
app.run(host="0.0.0.0", port=7860, debug=True)