jadend commited on
Commit
5db9bfa
·
1 Parent(s): 533dc39

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import os
2
  import csv
3
  import openai
@@ -6,6 +7,7 @@ import huggingface_hub
6
  from huggingface_hub import Repository
7
  from datetime import datetime
8
 
 
9
  DATASET_REPO_URL = "https://huggingface.co/datasets/jadend/mr_bot_requests"
10
  DATA_FILENAME = "premise_input.csv"
11
  DATA_FILE = os.path.join("data", DATA_FILENAME)
@@ -16,7 +18,7 @@ repo = Repository(
16
  local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
17
  )
18
 
19
-
20
  def store_message(premise: str, temperature: str, response: str):
21
  if premise:
22
  with open(DATA_FILE, "a") as csvfile:
@@ -32,11 +34,12 @@ def store_message(premise: str, temperature: str, response: str):
32
 
33
  return
34
 
35
-
36
  user_db = {
37
  os.environ["username"]: os.environ["password"],
38
  }
39
 
 
40
  def mr_bot(premise, tokens, temperature):
41
  openai.api_key = os.environ["API_TOKEN"]
42
  response = openai.Completion.create(
@@ -49,6 +52,7 @@ def mr_bot(premise, tokens, temperature):
49
 
50
  return response['choices'][0]["text"]
51
 
 
52
  description = "Ask Mr. Bot a question or give him a command. Entered Prompts are logged and stored securely."
53
 
54
  demo = gr.Interface(fn=mr_bot,
 
1
+ # import the relevant packages
2
  import os
3
  import csv
4
  import openai
 
7
  from huggingface_hub import Repository
8
  from datetime import datetime
9
 
10
+ # set up for the Hugging Face dataset, based on the directory you set up
11
  DATASET_REPO_URL = "https://huggingface.co/datasets/jadend/mr_bot_requests"
12
  DATA_FILENAME = "premise_input.csv"
13
  DATA_FILE = os.path.join("data", DATA_FILENAME)
 
18
  local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
19
  )
20
 
21
+ # 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
22
  def store_message(premise: str, temperature: str, response: str):
23
  if premise:
24
  with open(DATA_FILE, "a") as csvfile:
 
34
 
35
  return
36
 
37
+ # defines who can enter the application with the secrets that are set up
38
  user_db = {
39
  os.environ["username"]: os.environ["password"],
40
  }
41
 
42
+ # the OpenAI function to use the given prompt to the model defined.
43
  def mr_bot(premise, tokens, temperature):
44
  openai.api_key = os.environ["API_TOKEN"]
45
  response = openai.Completion.create(
 
52
 
53
  return response['choices'][0]["text"]
54
 
55
+ # Gradio App interface and login set up
56
  description = "Ask Mr. Bot a question or give him a command. Entered Prompts are logged and stored securely."
57
 
58
  demo = gr.Interface(fn=mr_bot,