PhilSpiel commited on
Commit
1ae9b86
·
1 Parent(s): 80eae57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -12,7 +12,7 @@ client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
12
 
13
  # Initialize empty history list to maintain the conversation context
14
  history_openai_format = [
15
- {"role": "system", "content": (os.getenv("PROMPT"))}
16
  ]
17
 
18
  # Define the function that takes a name and text input to generate the speech
@@ -67,17 +67,21 @@ def generate_speech(name, input_text):
67
  input=str(message_content)
68
  )
69
 
70
- # Prepare the transcript for the TextArea output
71
  # Exclude the system message from the transcript and show the user's actual input
72
  # Add line spaces between user and assistant output, and between user/assistant exchanges
73
  transcript = ""
 
74
  for i, msg in enumerate(history_openai_format):
75
  if msg['role'] != 'system':
76
  if msg['role'] == 'user':
77
- transcript += "Date/Time: " + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\n"
78
- transcript += f"Guest: {input_text}\n" # Change 'User' to 'Guest'
 
 
 
79
  else:
80
- transcript += f"Johnny: {msg['content']}\n\n" # Change 'Assistant' to 'Johnny'
81
 
82
  # Write the user and assistant messages to the history file after the exchange
83
  with open(user_hist_file, "a+", encoding="UTF-8") as file:
 
12
 
13
  # Initialize empty history list to maintain the conversation context
14
  history_openai_format = [
15
+ {"role": "system", "content": os.getenv("PROMPT")}
16
  ]
17
 
18
  # Define the function that takes a name and text input to generate the speech
 
67
  input=str(message_content)
68
  )
69
 
70
+ # Prepare the transcript for the Textbox output
71
  # Exclude the system message from the transcript and show the user's actual input
72
  # Add line spaces between user and assistant output, and between user/assistant exchanges
73
  transcript = ""
74
+ transcript += "Date/Time: " + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\n\n"
75
  for i, msg in enumerate(history_openai_format):
76
  if msg['role'] != 'system':
77
  if msg['role'] == 'user':
78
+ # Extract the actual user input from the message content instead of using the latest input_text
79
+ # Assuming input_text1 = f"I'm {name}. " + input_text, you must remove the "I'm {name}. " part.
80
+ user_input = msg['content'].split(". ", 1)[1] if ". " in msg['content'] else msg['content']
81
+ # Use the user_input for the Guest's content
82
+ transcript += f"GUEST: {user_input}\n"
83
  else:
84
+ transcript += f"JOHNNY: {msg['content']}\n\n"
85
 
86
  # Write the user and assistant messages to the history file after the exchange
87
  with open(user_hist_file, "a+", encoding="UTF-8") as file: