kavansaun commited on
Commit
494b3f6
·
verified ·
1 Parent(s): 6ce4077

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  import openai
3
  import os
4
  from github import Github
5
- import random
6
 
7
  # Load openai key
8
  openai.api_key = os.getenv('OPENAI_KEY')
@@ -17,8 +17,12 @@ message_history.append({"role": "user", "content": instructions})
17
  # Message for User Interface
18
  initial_message = "Please write your prompt here and press 'enter'"
19
 
20
- # Creating a random number for the user id
21
- random_int = random.randint(1, 100000)
 
 
 
 
22
 
23
  # Add token and connect to repository
24
  token = "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"
@@ -26,7 +30,7 @@ g = Github(token)
26
 
27
  # Creating a new file with the user id to save the user responses and chat bot responses to the repository
28
  repo = g.get_user().get_repo("CATData")
29
- filename = 'User:' + str(random_int) + '_Data.txt'
30
  repo.create_file(filename, "Saving" + filename, "")
31
 
32
  # Create function to process prompt and append previous prompts as "context"
@@ -71,7 +75,7 @@ def predict_prompt(input):
71
  # Create UI using gradio
72
  with gr.Blocks(theme=gr.themes.Monochrome()) as chatblock:
73
 
74
- gr.Markdown("<h1><center>" + "Please type the id: " + str(random_int) + " in the user id question underneath the Chat Bot" + "</center></h1>")
75
 
76
  Chatbot = gr.Chatbot()
77
  with gr.Row():
 
2
  import openai
3
  import os
4
  from github import Github
5
+ import uuid
6
 
7
  # Load openai key
8
  openai.api_key = os.getenv('OPENAI_KEY')
 
17
  # Message for User Interface
18
  initial_message = "Please write your prompt here and press 'enter'"
19
 
20
+ # Creating a unique id for the user
21
+ def generate_unique_id():
22
+ return str(uuid.uuid4())
23
+
24
+ # Example usage
25
+ unique_id = generate_unique_id()
26
 
27
  # Add token and connect to repository
28
  token = "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"
 
30
 
31
  # Creating a new file with the user id to save the user responses and chat bot responses to the repository
32
  repo = g.get_user().get_repo("CATData")
33
+ filename = 'User:' + str(unique_id) + '_Data.txt'
34
  repo.create_file(filename, "Saving" + filename, "")
35
 
36
  # Create function to process prompt and append previous prompts as "context"
 
75
  # Create UI using gradio
76
  with gr.Blocks(theme=gr.themes.Monochrome()) as chatblock:
77
 
78
+ gr.Markdown("<h1><center>" + "Please type the id: " + str(unique_id) + " in the user id question underneath the Chat Bot" + "</center></h1>")
79
 
80
  Chatbot = gr.Chatbot()
81
  with gr.Row():