Vedika commited on
Commit
d172eee
·
verified ·
1 Parent(s): 57be3ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -4
app.py CHANGED
@@ -1,6 +1,9 @@
1
  import os
 
 
2
  import requests
3
- from flask import Flask, request, Response, stream_with_context, render_template_string
 
4
 
5
  app = Flask(__name__)
6
 
@@ -36,7 +39,7 @@ def chat():
36
  user_message = data.get("message", "")
37
  attachments = data.get("attachments", [])
38
  system_prompt = data.get("system_prompt", "")
39
- history = data.get("history", []) # <-- यहँ मैं हिस्ट्री को रिसीव करने का कोड जोड़ा है
40
  max_tokens = data.get("max_tokens", 4096)
41
  temperature = data.get("temperature", 0.6)
42
 
@@ -46,7 +49,7 @@ def chat():
46
  if system_prompt.strip():
47
  messages.append({"role": "system", "content": system_prompt})
48
 
49
- # 2. पुरानी हिस्ट्री (Memory) जोड़ना ताकि अर्जुन पुरानी बातें याद रखे <-- यह ब्लॉक नया जोड़ा गया है
50
  for msg in history:
51
  role = msg.get("role", "user")
52
  content = msg.get("content", "")
@@ -101,5 +104,31 @@ def chat():
101
  except Exception as e:
102
  return Response("Internal Error: Unable to process request securely.", status=500)
103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  if __name__ == '__main__':
105
- app.run(host='0.0.0.0', port=7860)
 
1
  import os
2
+ import asyncio
3
+ import tempfile
4
  import requests
5
+ import edge_tts
6
+ from flask import Flask, request, Response, stream_with_context, render_template_string, send_file
7
 
8
  app = Flask(__name__)
9
 
 
39
  user_message = data.get("message", "")
40
  attachments = data.get("attachments", [])
41
  system_prompt = data.get("system_prompt", "")
42
+ history = data.get("history", []) # पुरान हिस्ट्री (Memory)
43
  max_tokens = data.get("max_tokens", 4096)
44
  temperature = data.get("temperature", 0.6)
45
 
 
49
  if system_prompt.strip():
50
  messages.append({"role": "system", "content": system_prompt})
51
 
52
+ # 2. पुरानी हिस्ट्री (Memory) जोड़ना ताकि अर्जुन पुरानी बातें याद रखे
53
  for msg in history:
54
  role = msg.get("role", "user")
55
  content = msg.get("content", "")
 
104
  except Exception as e:
105
  return Response("Internal Error: Unable to process request securely.", status=500)
106
 
107
+
108
+ # 🎙️ नया TTS एंडपॉइंट (Microsoft Edge - Prabhat Neural)
109
+ @app.route('/api/tts', methods=['POST'])
110
+ def tts():
111
+ data = request.get_json() or {}
112
+ text = data.get("text", "")
113
+
114
+ if not text:
115
+ return Response("No text provided", status=400)
116
+
117
+ # एक टेम्परेरी MP3 फाइल बनाना
118
+ temp_path = tempfile.mktemp(suffix=".mp3")
119
+
120
+ # आवाज़ को भारी (Heavy/Deep) करने के लिए pitch को कम किया गया है (-20%)
121
+ # Prabhat Neural की आवाज सेट की गई है।
122
+ async def generate_audio():
123
+ communicate = edge_tts.Communicate(text, "en-IN-PrabhatNeural", pitch="-20%", rate="-5%")
124
+ await communicate.save(temp_path)
125
+
126
+ try:
127
+ asyncio.run(generate_audio())
128
+ return send_file(temp_path, mimetype="audio/mpeg", as_attachment=False)
129
+ except Exception as e:
130
+ return Response(f"TTS Error: {str(e)}", status=500)
131
+
132
+
133
  if __name__ == '__main__':
134
+ app.run(host='0.0.0.0', port=7860)