Spaces:
Sleeping
Sleeping
Add instructions on how to duplicate/customize the Space
Browse files- README.md +34 -1
- brand_tune/app.py +33 -5
- brand_tune/prompting.py +0 -2
README.md
CHANGED
@@ -20,4 +20,37 @@ Run the following from the terminal:
|
|
20 |
```sh
|
21 |
poetry install
|
22 |
poetry run gradio app.py
|
23 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
```sh
|
21 |
poetry install
|
22 |
poetry run gradio app.py
|
23 |
+
```
|
24 |
+
|
25 |
+
## Customization
|
26 |
+
|
27 |
+
Interested in using Brand Tune for your own brand?
|
28 |
+
Begin by duplicating this Hugging Face Space.
|
29 |
+
There should be a button with a vertical "..." in the top right.
|
30 |
+
If you expand it, there's a "Duplicate this Space" option β click it.
|
31 |
+
|
32 |
+
Select the name you want to use.
|
33 |
+
The hardware is not important, so pick the cheapest option.
|
34 |
+
The actual computation takes place via the OpenAI API,
|
35 |
+
so you will need to fill in the `OPENAI_API_KEY` space secret.
|
36 |
+
See [here](https://help.openai.com/en/articles/4936850-where-do-i-find-my-secret-api-key)
|
37 |
+
on how to get one.
|
38 |
+
|
39 |
+
This will give you a copy of the space that you can edit.
|
40 |
+
|
41 |
+
### Brand guidelines
|
42 |
+
|
43 |
+
Next, edit `meta_prompt.txt` to describe the style you're looking for.
|
44 |
+
|
45 |
+
You can also provide an example input/output pair - like "write an instagram post about X"
|
46 |
+
and then an example of what a good answer would look like.
|
47 |
+
This can help guide ChatGPT to follow the style you want.
|
48 |
+
First, go to `app.py` and set `USE_EXAMPLE = True`.
|
49 |
+
Then put the example input into `example_input.txt` and the corresponding output into `example_output.txt`.
|
50 |
+
|
51 |
+
### Changing the password
|
52 |
+
|
53 |
+
In the chatbot, type "/password [the password you want]".
|
54 |
+
This will give you instructions on how to change the password β you'll need to edit `brand_tune/app.py`.
|
55 |
+
|
56 |
+
If your Space is public, this will prevent unknown people from using your OpenAI API.
|
brand_tune/app.py
CHANGED
@@ -8,8 +8,12 @@ import hashlib
|
|
8 |
SALT = "this is some random text 4e881d478cbeb1f6e5cb416770"
|
9 |
CORRECT_HASH = "222632858bf11308f0a7d41cb9fc061a51a47c98da85699706cc663b24aed55e"
|
10 |
|
|
|
|
|
|
|
11 |
|
12 |
-
|
|
|
13 |
return hashlib.sha256((password + SALT).encode()).hexdigest()
|
14 |
|
15 |
|
@@ -20,7 +24,7 @@ def gradio_history_to_openai_history(gradio_history: list[list[str]]):
|
|
20 |
"content": prompting.PROMPT_TEMPLATE,
|
21 |
},
|
22 |
]
|
23 |
-
if
|
24 |
openai_history += [
|
25 |
{"role": "user", "content": prompting.EXAMPLE_INPUT},
|
26 |
{"role": "assistant", "content": prompting.EXAMPLE_OUTPUT},
|
@@ -35,18 +39,42 @@ def gradio_history_to_openai_history(gradio_history: list[list[str]]):
|
|
35 |
|
36 |
|
37 |
def bot(history: list[list[str]]):
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
history[-1][1] = "Correct! You can now use the chatbot."
|
40 |
yield history
|
41 |
return
|
42 |
else:
|
43 |
found = False
|
44 |
for user_message, bot_message in history:
|
45 |
-
if
|
46 |
found = True
|
47 |
break
|
48 |
if not found:
|
49 |
-
history[-1][1] = "Incorrect password. Try again."
|
50 |
yield history
|
51 |
return
|
52 |
|
|
|
8 |
SALT = "this is some random text 4e881d478cbeb1f6e5cb416770"
|
9 |
CORRECT_HASH = "222632858bf11308f0a7d41cb9fc061a51a47c98da85699706cc663b24aed55e"
|
10 |
|
11 |
+
# Use the example input and output from example_input.txt and example_output.txt?
|
12 |
+
# This can help in specifying the style you'd like to use.
|
13 |
+
USE_EXAMPLE = True
|
14 |
|
15 |
+
|
16 |
+
def hash_password(password: str):
|
17 |
return hashlib.sha256((password + SALT).encode()).hexdigest()
|
18 |
|
19 |
|
|
|
24 |
"content": prompting.PROMPT_TEMPLATE,
|
25 |
},
|
26 |
]
|
27 |
+
if USE_EXAMPLE:
|
28 |
openai_history += [
|
29 |
{"role": "user", "content": prompting.EXAMPLE_INPUT},
|
30 |
{"role": "assistant", "content": prompting.EXAMPLE_OUTPUT},
|
|
|
39 |
|
40 |
|
41 |
def bot(history: list[list[str]]):
|
42 |
+
last_message = history[-1][0]
|
43 |
+
|
44 |
+
if last_message == "/help":
|
45 |
+
history[-1][1] = (
|
46 |
+
"Welcome to Brand Tune, the tool that helps you keep your brand consistent. "
|
47 |
+
"First, you'll need to enter a password to be able to use the chatbot. "
|
48 |
+
"This is so that unauthorized people don't use the OpenAI API that we "
|
49 |
+
"have to pay for.\n"
|
50 |
+
"For more info, like how to make your own version, "
|
51 |
+
"go to the Files tab and check out README.md."
|
52 |
+
)
|
53 |
+
yield history
|
54 |
+
return
|
55 |
+
|
56 |
+
if last_message.startswith("/password "):
|
57 |
+
password = last_message[len("/password ") :]
|
58 |
+
h = hash_password(password)
|
59 |
+
history[-1][1] = (
|
60 |
+
f'To change the password to "{password}", edit brand_tune/app.py and change '
|
61 |
+
f'the relevant line to:\nCORRECT_HASH = "{h}"'
|
62 |
+
)
|
63 |
+
yield history
|
64 |
+
return
|
65 |
+
|
66 |
+
if hash_password(last_message) == CORRECT_HASH:
|
67 |
history[-1][1] = "Correct! You can now use the chatbot."
|
68 |
yield history
|
69 |
return
|
70 |
else:
|
71 |
found = False
|
72 |
for user_message, bot_message in history:
|
73 |
+
if hash_password(user_message) == CORRECT_HASH:
|
74 |
found = True
|
75 |
break
|
76 |
if not found:
|
77 |
+
history[-1][1] = "Incorrect password. Try again. Type /help for help."
|
78 |
yield history
|
79 |
return
|
80 |
|
brand_tune/prompting.py
CHANGED
@@ -9,5 +9,3 @@ with (this_dir.parent / "example_input.txt").open() as f:
|
|
9 |
|
10 |
with (this_dir.parent / "example_output.txt").open() as f:
|
11 |
EXAMPLE_OUTPUT = f.read()
|
12 |
-
|
13 |
-
USE_EXAMPLE = False
|
|
|
9 |
|
10 |
with (this_dir.parent / "example_output.txt").open() as f:
|
11 |
EXAMPLE_OUTPUT = f.read()
|
|
|
|