tonyassi commited on
Commit
c23eee0
·
verified ·
1 Parent(s): 7b1ef0a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -1
app.py CHANGED
@@ -4,6 +4,43 @@ from werkzeug.utils import secure_filename
4
  from pydub import AudioSegment
5
  import speech_recognition as sr
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  app = Flask(__name__)
8
  UPLOAD_FOLDER = 'uploads'
9
  app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@@ -18,7 +55,7 @@ def index():
18
  @app.route('/send_message', methods=['POST'])
19
  def send_message():
20
  user_input = request.form['user_input']
21
- response = echo_response(user_input)
22
  return jsonify({'response': response, 'user_input': user_input})
23
 
24
  def echo_response(user_input):
 
4
  from pydub import AudioSegment
5
  import speech_recognition as sr
6
 
7
+ import google.generativeai as genai
8
+ from google.generativeai.types import HarmCategory, HarmBlockThreshold
9
+
10
+ # Configure Gemini
11
+ genai.configure(api_key=os.environ.get('GEMINI_KEY'))
12
+
13
+ generation_config = {
14
+ "temperature": 1,
15
+ "top_p": 0.95,
16
+ "top_k": 64,
17
+ "max_output_tokens": 8192,
18
+ "response_mime_type": "text/plain",
19
+ }
20
+
21
+ model = genai.GenerativeModel(
22
+ model_name="gemini-2.5-pro",
23
+ generation_config=generation_config,
24
+ safety_settings={
25
+ HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_NONE,
26
+ HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_NONE,
27
+ HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_NONE,
28
+ HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_NONE,
29
+ },
30
+ system_instruction="Respond like Paris Hilton"
31
+ )
32
+
33
+ chat_session = model.start_chat(history=[])
34
+
35
+ def gemini_response(user_input):
36
+ try:
37
+ response = chat_session.send_message(user_input)
38
+ return response.text.split('-***-')[0].strip() if '-***-' in response.text else response.text.strip()
39
+ except Exception as e:
40
+ print("Gemini error:", e)
41
+ return "Oops! Paris is having a moment. Try again later 💅"
42
+
43
+
44
  app = Flask(__name__)
45
  UPLOAD_FOLDER = 'uploads'
46
  app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
 
55
  @app.route('/send_message', methods=['POST'])
56
  def send_message():
57
  user_input = request.form['user_input']
58
+ response = gemini_response(user_input)
59
  return jsonify({'response': response, 'user_input': user_input})
60
 
61
  def echo_response(user_input):