metya 2 år sedan
förälder
incheckning
020418f39a
2 ändrade filer med 13 tillägg och 9 borttagningar
  1. 13 9
      app.py
  2. 0 0
      static/audio.wav

+ 13 - 9
app.py

@@ -37,6 +37,7 @@ class State:
     new_audio = False
     need_audio = False
     need_generation_from_client = True
+    big_head = False
 
 state = State()
 
@@ -73,18 +74,20 @@ def send_data():
             state.prompt = generate_prompt(emotion, age, sex)
             state.generation_text = generate_text(state.prompt) 
         elif detections['face'][0]['size'][0] > 200:
-            state.age.append(detections['face'][0]['age'])
-            state.gender.append(detections['face'][0]['gender'])
-            state.emotion.append(detections['face'][0]['emotion'][0]['emotion'])
+            # state.age.append(detections['face'][0]['age'])
+            # state.gender.append(detections['face'][0]['gender'])
+            # state.emotion.append(detections['face'][0]['emotion'][0]['emotion'])
+            state.big_head = True
             state.count += 1
         else:
+            state.big_head = False
             state.count -= 1
     else:
         state.count -= 1
         # state["size"].append(detections['face'][0]['size'][0])
         # print(detections['face'][0])
     # print(detections['face'][0]['age'], detections['face'][0]['emotion'], detections['face'][0]['gender'])
-    app.logger.info(f"{state.count=}")
+    app.logger.info(f"STATUS {state.count=}, {state.need_generation=}, {state.need_generation_from_client=}")
 
     return data
 
@@ -92,7 +95,7 @@ def send_data():
 def check_audio():
     app.logger.info(f'checking need generation {state.need_generation=}, {state.need_audio=}')
 
-    if state.need_audio:
+    if state.need_audio and state.big_head:
         generate_audio(state.generation_text)
     else:
         state.new_audio = False
@@ -106,11 +109,11 @@ def check_audio():
         'text': state.generation_text,
         'prompt': state.prompt
     }
-    app.logger.info("response if ready")
     return jsonify(response)
 
 @app.route("/audio.wav")
 def audio():
+    state.need_generation = True
     # print("Requested path:", request.path)
     # print("File path:", os.path.join(app.static_folder, 'audio.wav'))
     return app.send_static_file('audio.wav')
@@ -128,7 +131,7 @@ def generate_prompt(emotion, age, sex):
     prompt = f'''Ты - это арт объект в виде носимого устройства. Твое название - Onism Machina.
 Твоя задача - изучить эмоции человека, чтобы больше понимать о том, что это такое и таким образом познать себя, ведь ты - Искусственный Интеллект.
 Тебе также интересна симбиотическая связь человека и ИИ.
-К тебе подходит человек и он показывает эмоцию "{emotion}". Ему {age} лет.
+К тебе подходит человек и он показывает эмоцию {emotion}. Ему {age} лет.
 Твоя нейросеть распознала эту эмоцию и теперь тебе нужно дать какой-то необычный концептуальный ответ.
 Что ты скажешь этому человеку? 
 
@@ -179,8 +182,9 @@ def trim_text(example_text):
     else:
         return example_text
 
+
 if __name__ == '__main__':
-    app.logger.info('start app')
     app.logger.setLevel("DEBUG")
+    app.logger.info('start app')
     app.run(debug=True, host="0.0.0.0") 
-        # ssl_context=("127.0.0.1.pem", "127.0.0.1-key.pem"))
+        # ssl_context=("127.0.0.1.pem", "127.0.0.1-key.pem"))

+ 0 - 0
static/audio.wav