Spaces:
Running
Running
Utkarsh Verma
commited on
Commit
Β·
bb41b4b
1
Parent(s):
0643817
Code Change
Browse files
app.py
CHANGED
@@ -15,15 +15,16 @@ def home():
|
|
15 |
return render_template('index.html')
|
16 |
|
17 |
@app.route('/chat', methods=['POST'])
|
18 |
-
def chat(
|
19 |
user_message = request.json.get("message")
|
20 |
|
21 |
if not user_message:
|
22 |
return jsonify({"error": "Empty message received"})
|
23 |
|
24 |
try:
|
|
|
25 |
payload = {
|
26 |
-
"inputs":
|
27 |
"parameters": {
|
28 |
"temperature": 0.5, # π₯ Controls randomness (lower = more deterministic)
|
29 |
"top_p": 0.9, # π― Focus on high-probability words
|
@@ -46,7 +47,8 @@ def chat(user_input):
|
|
46 |
if "error" in data:
|
47 |
return jsonify({"reply": f"Error: {data['error']}"})
|
48 |
|
49 |
-
|
|
|
50 |
return jsonify({"reply": reply})
|
51 |
|
52 |
except Exception as e:
|
|
|
15 |
return render_template('index.html')
|
16 |
|
17 |
@app.route('/chat', methods=['POST'])
|
18 |
+
def chat():
|
19 |
user_message = request.json.get("message")
|
20 |
|
21 |
if not user_message:
|
22 |
return jsonify({"error": "Empty message received"})
|
23 |
|
24 |
try:
|
25 |
+
formatted_prompt = f"User: {user_message}\nBot:"
|
26 |
payload = {
|
27 |
+
"inputs": formatted_prompt,
|
28 |
"parameters": {
|
29 |
"temperature": 0.5, # π₯ Controls randomness (lower = more deterministic)
|
30 |
"top_p": 0.9, # π― Focus on high-probability words
|
|
|
47 |
if "error" in data:
|
48 |
return jsonify({"reply": f"Error: {data['error']}"})
|
49 |
|
50 |
+
raw_output = data[0]['generated_text'] if isinstance(data, list) else data.get('generated_text', "No response")
|
51 |
+
reply = raw_output.split("Bot:")[-1].strip()
|
52 |
return jsonify({"reply": reply})
|
53 |
|
54 |
except Exception as e:
|