metya hace 2 años
padre
commit
774306957d
Se han modificado 2 ficheros con 11 adiciones y 14 borrados
  1. 4 3
      .gitignore
  2. 7 11
      app.py

+ 4 - 3
.gitignore

@@ -6,6 +6,9 @@ __pycache__/
 # C extensions
 *.so
 
+# audio
+*.wav
+
 # Distribution / packaging
 .Python
 build/
@@ -158,6 +161,4 @@ cython_debug/
 #  be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
 #  and can be added to the global gitignore or merged into this file.  For a more nuclear
 #  option (not recommended) you can uncomment the following to ignore the entire idea folder.
-#.idea/
-
-*.wav
+#.idea/

+ 7 - 11
app.py

@@ -52,13 +52,14 @@ def send_data():
     data = request.form['data']
     need_generation = request.form['state']
     state.need_generation_from_client = (need_generation in ["true", "True"])
-    if state.need_generation_from_client and state.count > 20:
+    # if state.need_generation_from_client and 
+    if state.count < -10 or state.count > 60:
         state.count = 0
         state.need_generation = True
 
     # Обработка полученных данных
     detections = json.loads(data)
-    if detections['face']:
+    if len(detections['face']) > 0:
         if state.count < 0 or state.new_audio: state.count = 0
         if state.count > 5 and state.need_generation and state.need_generation_from_client:
             app.logger.info(f"time for generation {state.count=}, {state.need_generation=}, {state.need_generation_from_client=}")
@@ -84,9 +85,7 @@ def send_data():
             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"STATUS {state.count=}, {state.need_generation=}, {state.need_generation_from_client=}")
 
     return data
@@ -114,8 +113,6 @@ def check_audio():
 @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')
 
 
@@ -152,7 +149,7 @@ def generate_text(prompt):
     response = openai.ChatCompletion.create(
                         model="gpt-3.5-turbo",
                         temperature=1,
-                        max_tokens=1000,
+                        max_tokens=800,
                         messages=[
                                 {"role": "system", "content": "Ты — это арт объект выставки про взаимодействие машины и человека."},
                                 {"role": "user", "content": prompt},
@@ -175,7 +172,7 @@ def generate_audio(sample_text):
 
 def trim_text(example_text):
     if len(example_text) >= 1000:
-        app.logger.info('TEXT IS TOO LONG - TRIM!')
+        app.logger.info(f'TEXT IS TOO LONG {len(example_text)} - TRIM!')
         for i in range(1000, 500, -1):
             if example_text[i] in ['.', '?', '...']:
                 return example_text[:i+1]
@@ -186,5 +183,4 @@ def trim_text(example_text):
 if __name__ == '__main__':
     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"))
+    app.run(debug=True, host="0.0.0.0")