kavansaun commited on
Commit
0d640db
·
verified ·
1 Parent(s): c475a85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -21,7 +21,7 @@ client = OpenAI(api_key=openai_key)
21
  g = Github(github_key) if github_key else None
22
 
23
  # Repo name, if you want to save to a github repository change RepositoryName to your repo name, name must be under quotations
24
- REPO_NAME = "CATDATA1"
25
 
26
  # Session data for each user
27
  user_dictionary = {}
@@ -46,7 +46,7 @@ def update_github_log(uid):
46
  repo.create_file(filename, "Create session log", content)
47
  except Exception as e:
48
  error_msg = str(e).lower()
49
- # Catch invalid GitHub keys and raise a UI error
50
  if "bad_credentials" in error_msg or "bad credentials" in error_msg:
51
  gr.Warning("The GitHub API Key provided is invalid.")
52
  elif "repository" in error_msg or "404" in error_msg:
@@ -73,7 +73,7 @@ with gr.Blocks(theme=gr.themes.Monochrome(), css="""footer {display:none !import
73
  print(f"Session started. User ID: {new_id}") # Cleaned up console print
74
  user_dictionary[new_id] = []
75
 
76
- # INSTRUCTIONS, instructions must be in quotations, \n means a new line to the AI.
77
  instructions = (
78
  "You are a Chat Bot for the KU HMC Lab\n"
79
  "instruction...\n"
@@ -112,7 +112,7 @@ with gr.Blocks(theme=gr.themes.Monochrome(), css="""footer {display:none !import
112
 
113
  return formatted_chat, ""
114
 
115
- # Optional function to simulate the time it takes a "person" to read your message, (amount of time reading, bubbles dont show up).
116
  def pause_before_typing(user_id):
117
  # Calculate reading time based on the length of the user's message
118
  if user_id and user_id in user_dictionary and len(user_dictionary[user_id]) > 0:
@@ -136,14 +136,13 @@ with gr.Blocks(theme=gr.themes.Monochrome(), css="""footer {display:none !import
136
  )
137
  reply = response.choices[0].message.content
138
 
139
- # Optional delay for a realistic human response time (amount of time typing message, bubbles show up)
140
- # Dynamically calculated based on the length of the chatbot's generated reply
141
  typing_delay = max(1.0, min(len(reply) / 40, 5.0)) # Caps typing delay between 1 and 5 seconds
142
  time.sleep(typing_delay)
143
 
144
  except Exception as e:
145
  error_msg = str(e).lower()
146
- # Catch invalid or expired API keys and show a clean error message
147
  if "invalid_api_key" in error_msg or "incorrect api key" in error_msg:
148
  gr.Warning("The OpenAI API Key provided is invalid or expired.")
149
  reply = "System Error: The OpenAI API Key is invalid."
 
21
  g = Github(github_key) if github_key else None
22
 
23
  # Repo name, if you want to save to a github repository change RepositoryName to your repo name, name must be under quotations
24
+ REPO_NAME = "RepositoryName"
25
 
26
  # Session data for each user
27
  user_dictionary = {}
 
46
  repo.create_file(filename, "Create session log", content)
47
  except Exception as e:
48
  error_msg = str(e).lower()
49
+ # Catch invalid GitHub keys and raise a error
50
  if "bad_credentials" in error_msg or "bad credentials" in error_msg:
51
  gr.Warning("The GitHub API Key provided is invalid.")
52
  elif "repository" in error_msg or "404" in error_msg:
 
73
  print(f"Session started. User ID: {new_id}") # Cleaned up console print
74
  user_dictionary[new_id] = []
75
 
76
+ # INSTRUCTIONS, instructions must be in quotations, \n means a new line to the AI (not needed).
77
  instructions = (
78
  "You are a Chat Bot for the KU HMC Lab\n"
79
  "instruction...\n"
 
112
 
113
  return formatted_chat, ""
114
 
115
+ # Optional function to simulate the time it takes a "person" to read the users message, (amount of time reading, bubbles dont show up).
116
  def pause_before_typing(user_id):
117
  # Calculate reading time based on the length of the user's message
118
  if user_id and user_id in user_dictionary and len(user_dictionary[user_id]) > 0:
 
136
  )
137
  reply = response.choices[0].message.content
138
 
139
+ # Optional delay for a "human" response time based on the length of the chatbot's reply (amount of time typing message, bubbles show up)
 
140
  typing_delay = max(1.0, min(len(reply) / 40, 5.0)) # Caps typing delay between 1 and 5 seconds
141
  time.sleep(typing_delay)
142
 
143
  except Exception as e:
144
  error_msg = str(e).lower()
145
+ # Catch invalid or expired API keys and show a error message
146
  if "invalid_api_key" in error_msg or "incorrect api key" in error_msg:
147
  gr.Warning("The OpenAI API Key provided is invalid or expired.")
148
  reply = "System Error: The OpenAI API Key is invalid."