File size: 852 Bytes
35666dc c138cbc 335f4a7 c138cbc 335f4a7 35666dc 335f4a7 c138cbc 335f4a7 35666dc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
from flask import Flask, request, jsonify, render_template
from llama_cpp import Llama
app = Flask(__name__)
# Load the Llama model (Ensure the GGUF file is in the same directory)
llm = Llama.from_pretrained(
repo_id="bartowski/google_gemma-3-1b-it-GGUF",
filename="google_gemma-3-1b-it-IQ4_XS.gguf",
)
@app.route("/")
def home():
return render_template("index.html")
@app.route("/chat", methods=["POST"])
def chat():
user_input = request.json.get("message", "")
if not user_input:
return jsonify({"error": "Empty input"}), 400
response = llm.create_chat_completion(
messages=[{"role": "user", "content": user_input}]
)
bot_reply = response["choices"][0]["message"]["content"]
return jsonify({"response": bot_reply})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=7860)
|