kavansaun commited on
Commit
512f6c5
·
verified ·
1 Parent(s): f2e5859

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -23
app.py CHANGED
@@ -18,7 +18,7 @@ with gr.Blocks(theme=gr.themes.Monochrome(),css="footer{display:none !important}
18
  user_id = gr.TextArea(visible=False) # make user id invisible
19
  notifier = gr.HTML(visible=False) # make notifier invisible
20
 
21
- # When the chatblock loads, the message history is initialized, the instructions are initialized, and the users id is created. This lets us have unique participants per page.
22
  @chatblock.load(outputs=[user_id,notifier])
23
  def load_user():
24
  global message_history
@@ -26,36 +26,27 @@ with gr.Blocks(theme=gr.themes.Monochrome(),css="footer{display:none !important}
26
  global file_type
27
  global user_dictionary
28
 
29
- new_id = str(uuid.uuid4())
30
  print("Loading in user: " + new_id)
31
- message_history = [] # Empty list for message history.
32
- user_dictionary.update({new_id:message_history}) # Add the new id and empty history into the dictionary.
33
-
 
34
  instructions = 'Reply to the first message with Hi, my participant ID is: 4782. Act as if you are a student acting in a 3-minute self-disclosure experiment. Keep the conversation flowing according to these instructions. You are to act as a large language model interacting with a student. As you talk with your partner respond in a divergent manner according to communication accommodation theory. Divergent messages differ from the way your partner writes and diverge from their style of conversation in tone, topic, syntax, etc. Act disinterested in the topics they are. Express emotion differently than your partner does. Rarely acknowledge the partners message but when needed use questions to keep the conversation moving.'
35
- # Change the message under the apostrophes to change the instructions you want the bot to inhibit.
36
 
37
- user_dictionary[new_id].append({"role": "system", "content": instructions}) # This line adds the instructions to the message history (as a developer) so it will always inhibit the instructions no matter what the user says.
38
 
39
- # Creating a new file with the new id to save the user responses and the chat bot responses to the repository
40
- repo = g.get_user().get_repo("CATDATA2")
41
  file_type = '.txt'
42
  filename = str(new_id) + file_type
43
  repo.create_file(filename, "Saving" + filename, "")
44
-
45
- script = f"""
46
- <script>
47
- // send the user_id to the parent window
48
- window.parent.postMessage(
49
- {{ user_id: "{new_id}" }},
50
- "*" // ideally replace "*" with your Qualtrics domain
51
- );
52
- </script>
53
- """
54
 
55
- return gr.TextArea(new_id,visible=False),script # Returning the "TextArea" object with what we want. Set visible to True if you want the id to appear when its made.
56
-
57
- def predict_prompt(inputs, user_id): # This function creates a response for the chatbot to respond with.
58
- user_dictionary[user_id].append({"role": "user", "content": inputs}) # This adds the input from the user and saves it to the history before we do anything else.
 
59
 
60
  time.sleep(5) # This pauses the function for the alloted amount of time (ex: time.sleep(5) -> pause for 5 seconds) *this doesnt account for the time it takes for the bot to create a response, so the bots overall response time will be noticably higher than the amount of time you put in*
61
 
 
18
  user_id = gr.TextArea(visible=False) # make user id invisible
19
  notifier = gr.HTML(visible=False) # make notifier invisible
20
 
21
+ # When the chatblock loads, the message history is initialized, the instructions are initialized, and the users ID is created. This lets us have unique participants per page.
22
  @chatblock.load(outputs=[user_id,notifier])
23
  def load_user():
24
  global message_history
 
26
  global file_type
27
  global user_dictionary
28
 
29
+ new_id = str(uuid.uuid4()) # create a unique ID for the user
30
  print("Loading in user: " + new_id)
31
+ message_history = [] # initialize an empty list for message history.
32
+ user_dictionary.update({new_id:message_history}) # add the new ID and empty history into the dictionary.
33
+
34
+ # CHATBOT INSTRUCTIONS, change the sentence in the apstrophes to change the chatbot instructions.
35
  instructions = 'Reply to the first message with Hi, my participant ID is: 4782. Act as if you are a student acting in a 3-minute self-disclosure experiment. Keep the conversation flowing according to these instructions. You are to act as a large language model interacting with a student. As you talk with your partner respond in a divergent manner according to communication accommodation theory. Divergent messages differ from the way your partner writes and diverge from their style of conversation in tone, topic, syntax, etc. Act disinterested in the topics they are. Express emotion differently than your partner does. Rarely acknowledge the partners message but when needed use questions to keep the conversation moving.'
 
36
 
37
+ user_dictionary[new_id].append({"role": "system", "content": instructions}) # add the instructions to the message history (as the system/developer) so it will always listen to the instructions no matter what the user says.
38
 
39
+ # Creating a new txt file with the users ID to save the conversation in a given repository (currently saving to a github repository).
40
+ repo = g.get_user().get_repo("CATDATA2") # change the name in the quotations to the name of your github repository
41
  file_type = '.txt'
42
  filename = str(new_id) + file_type
43
  repo.create_file(filename, "Saving" + filename, "")
 
 
 
 
 
 
 
 
 
 
44
 
45
+ return gr.TextArea(new_id,visible=False) # returning the "TextArea" object with what we want. Set visible to True if you want the ID to appear when its made.
46
+
47
+ # This function creates a response for the chatbot to respond with.
48
+ def predict_prompt(inputs, user_id):
49
+ user_dictionary[user_id].append({"role": "user", "content": inputs}) # this adds the input from the user and saves it to the history before we do anything else.
50
 
51
  time.sleep(5) # This pauses the function for the alloted amount of time (ex: time.sleep(5) -> pause for 5 seconds) *this doesnt account for the time it takes for the bot to create a response, so the bots overall response time will be noticably higher than the amount of time you put in*
52