Update app.py
Browse files
app.py
CHANGED
@@ -3,20 +3,26 @@ from llama_cpp import Llama
|
|
3 |
|
4 |
app = Flask(__name__)
|
5 |
|
6 |
-
# Load the
|
|
|
7 |
llm = Llama.from_pretrained(
|
8 |
repo_id="bartowski/google_gemma-3-1b-it-GGUF",
|
9 |
filename="google_gemma-3-1b-it-IQ4_XS.gguf",
|
10 |
)
|
|
|
11 |
|
12 |
@app.route("/")
|
13 |
def home():
|
|
|
14 |
return render_template("index.html")
|
15 |
|
16 |
@app.route("/chat", methods=["POST"])
|
17 |
def chat():
|
18 |
user_input = request.json.get("message", "")
|
|
|
|
|
19 |
if not user_input:
|
|
|
20 |
return jsonify({"error": "Empty input"}), 400
|
21 |
|
22 |
response = llm.create_chat_completion(
|
@@ -24,9 +30,12 @@ def chat():
|
|
24 |
)
|
25 |
|
26 |
bot_reply = response["choices"][0]["message"]["content"]
|
27 |
-
|
|
|
28 |
return jsonify({"response": bot_reply})
|
29 |
|
30 |
if __name__ == "__main__":
|
31 |
-
|
|
|
|
|
32 |
|
|
|
3 |
|
4 |
app = Flask(__name__)
|
5 |
|
6 |
+
# Load the model
|
7 |
+
print("π Loading model... (this may take a while)")
|
8 |
llm = Llama.from_pretrained(
|
9 |
repo_id="bartowski/google_gemma-3-1b-it-GGUF",
|
10 |
filename="google_gemma-3-1b-it-IQ4_XS.gguf",
|
11 |
)
|
12 |
+
print("β
Model loaded!")
|
13 |
|
14 |
@app.route("/")
|
15 |
def home():
|
16 |
+
print("π’ Serving index.html")
|
17 |
return render_template("index.html")
|
18 |
|
19 |
@app.route("/chat", methods=["POST"])
|
20 |
def chat():
|
21 |
user_input = request.json.get("message", "")
|
22 |
+
print(f"π¬ Received message: {user_input}")
|
23 |
+
|
24 |
if not user_input:
|
25 |
+
print("β οΈ Empty input received!")
|
26 |
return jsonify({"error": "Empty input"}), 400
|
27 |
|
28 |
response = llm.create_chat_completion(
|
|
|
30 |
)
|
31 |
|
32 |
bot_reply = response["choices"][0]["message"]["content"]
|
33 |
+
print(f"π€ Bot response: {bot_reply}")
|
34 |
+
|
35 |
return jsonify({"response": bot_reply})
|
36 |
|
37 |
if __name__ == "__main__":
|
38 |
+
print("π Starting Flask app on port 7860")
|
39 |
+
app.run(host="0.0.0.0", port=7860, debug=True)
|
40 |
+
|
41 |
|