jadend commited on
Commit
7b5289a
·
1 Parent(s): abfe52c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -25
app.py CHANGED
@@ -9,16 +9,12 @@ from huggingface_hub import Repository
9
  from datetime import datetime
10
 
11
  client = OpenAI(
12
- # This is the default and can be omitted
13
  api_key=os.environ.get("API_TOKEN"),
14
  )
15
 
16
- #openai.api_key = os.environ.get("API_TOKEN")
17
- #client = OpenAI()
18
-
19
- # set up for the Hugging Face dataset, based on the directory you set up
20
  DATASET_REPO_URL = "https://huggingface.co/datasets/jadend/mr_bot_requests"
21
- DATA_FILENAME = "premise_input.csv"
22
  DATA_FILE = os.path.join("data", DATA_FILENAME)
23
 
24
  HF_TOKEN = os.environ.get("HF_TOKEN")
@@ -28,12 +24,12 @@ repo = Repository(
28
  )
29
 
30
  # function to store the message to the Hugging Face site, if you would like to add more columns or information to track add it here
31
- def store_message(premise: str, temperature: str, response: str):
32
- if premise:
33
  with open(DATA_FILE, "a") as csvfile:
34
- writer = csv.DictWriter(csvfile, fieldnames=["premise", "temperature", "response", "time"])
35
  writer.writerow(
36
- {"premise": premise,
37
  "temperature": temperature,
38
  "response": response,
39
  "time": str(datetime.now())}
@@ -43,22 +39,21 @@ def store_message(premise: str, temperature: str, response: str):
43
 
44
  return
45
 
46
- # defines who can enter the application with the secrets that are set up
47
  user_db = {
48
  os.environ["username"]: os.environ["password"],
49
  }
50
 
51
  # the OpenAI function to use the given prompt to the model defined.
52
- def mr_bot(premise, tokens, temperature):
53
  response = client.chat.completions.create(
54
  model="gpt-3.5-turbo",
55
- messages=[{"role": "user", "content": premise}],
56
  max_tokens=tokens,
57
  temperature=temperature,
58
  )
59
- store_message(premise=premise, temperature=temperature, response=response.choices[0].message.content)
60
 
61
- # return response['choices'][0]["text"]
62
  return response.choices[0].message.content
63
 
64
 
@@ -67,26 +62,21 @@ description = "Use the examples below to see how different prompts generate diff
67
 
68
  demo = gr.Interface(fn=mr_bot,
69
  inputs=[gr.Textbox(placeholder="Select an example", interactive=False), gr.Slider(1, 800, default=800), gr.Slider(0.1, 1, default=0.75)],
70
- # inputs=[gr.Slider(1, 800, default=800), gr.Slider(0.1, 1, default=0.75)],
71
  outputs="text",
72
  title="Intro to AI Assignment",
73
  description=description,
74
  cache_examples=False,
75
  examples = [
76
- # Story Continuation:
77
- ["In a magical forest, a talking frog met a weary traveler. The frog said,", 800, .95],
78
  # Open-ended Question:
79
  ["What are some unconventional uses for a paperclip?", 800, .50],
80
- # Creative Writing:
81
- ["Write a poem about a sunset in a futuristic city.", 800, .70],
82
  # Invention Ideas:
83
  ["Imagine a new gadget that could change how we work from home. Describe it.", 800, .50],
84
- # Humorous Responses:
85
- ["Tell a funny story about a Corgi who thinks it's a Bunny.", 800, .80],
86
- # Fantasy Scenarios:
87
- ["Describe a day in the life of a wizard living in Philadelphia.", 800, .70],
88
  # Coding Scenario:
89
- ["Write me a function in python that involves rolling two 20-sided dice and adding them by a user inputted number.", 800, .50],
90
  # Office Tasking:
91
  ["Write me an email to my boss asking to meet about the upcoming conference.", 800, .50],
92
  ]
@@ -94,6 +84,7 @@ demo = gr.Interface(fn=mr_bot,
94
 
95
  if __name__ == "__main__":
96
  demo.launch(enable_queue=False,
 
97
  # auth=lambda u, p: user_db.get(u) == p,
98
  # auth_message="Welcome!"
99
  )
 
9
  from datetime import datetime
10
 
11
  client = OpenAI(
 
12
  api_key=os.environ.get("API_TOKEN"),
13
  )
14
 
15
+ # recording requests to Hugging Face dataset
 
 
 
16
  DATASET_REPO_URL = "https://huggingface.co/datasets/jadend/mr_bot_requests"
17
+ DATA_FILENAME = "prompt_input.csv"
18
  DATA_FILE = os.path.join("data", DATA_FILENAME)
19
 
20
  HF_TOKEN = os.environ.get("HF_TOKEN")
 
24
  )
25
 
26
  # function to store the message to the Hugging Face site, if you would like to add more columns or information to track add it here
27
+ def store_message(prompt: str, temperature: str, response: str):
28
+ if prompt:
29
  with open(DATA_FILE, "a") as csvfile:
30
+ writer = csv.DictWriter(csvfile, fieldnames=["prompt", "temperature", "response", "time"])
31
  writer.writerow(
32
+ {"prompt": prompt,
33
  "temperature": temperature,
34
  "response": response,
35
  "time": str(datetime.now())}
 
39
 
40
  return
41
 
42
+ # defines who can enter the application with the secrets that are set up if used
43
  user_db = {
44
  os.environ["username"]: os.environ["password"],
45
  }
46
 
47
  # the OpenAI function to use the given prompt to the model defined.
48
+ def mr_bot(prompt, tokens, temperature):
49
  response = client.chat.completions.create(
50
  model="gpt-3.5-turbo",
51
+ messages=[{"role": "user", "content": prompt}],
52
  max_tokens=tokens,
53
  temperature=temperature,
54
  )
55
+ store_message(prompt=prompt, temperature=temperature, response=response.choices[0].message.content)
56
 
 
57
  return response.choices[0].message.content
58
 
59
 
 
62
 
63
  demo = gr.Interface(fn=mr_bot,
64
  inputs=[gr.Textbox(placeholder="Select an example", interactive=False), gr.Slider(1, 800, default=800), gr.Slider(0.1, 1, default=0.75)],
 
65
  outputs="text",
66
  title="Intro to AI Assignment",
67
  description=description,
68
  cache_examples=False,
69
  examples = [
70
+ # Creative Writing:
71
+ ["Describe a day in the life of a wizard with a Corgi sidekick living in Philadelphia.", 800, .95],
72
  # Open-ended Question:
73
  ["What are some unconventional uses for a paperclip?", 800, .50],
74
+ # Sentiment Analysis:
75
+ ["How has consumer sentiment changed since the pandemic?", 800, .60],
76
  # Invention Ideas:
77
  ["Imagine a new gadget that could change how we work from home. Describe it.", 800, .50],
 
 
 
 
78
  # Coding Scenario:
79
+ ["Write me a function in python that involves rolling two 20-sided die and adding them by a user generated number.", 800, .40],
80
  # Office Tasking:
81
  ["Write me an email to my boss asking to meet about the upcoming conference.", 800, .50],
82
  ]
 
84
 
85
  if __name__ == "__main__":
86
  demo.launch(enable_queue=False,
87
+ # if authentication is needed, uncomment below
88
  # auth=lambda u, p: user_db.get(u) == p,
89
  # auth_message="Welcome!"
90
  )