Spaces:
Runtime error
Runtime error
updates
Browse files
app.py
CHANGED
@@ -5,7 +5,6 @@ from langchain.chains import SimpleSequentialChain
|
|
5 |
from langchain.llms import OpenAI
|
6 |
from langchain.prompts import PromptTemplate
|
7 |
from langchain.chains import SequentialChain
|
8 |
-
|
9 |
import openai
|
10 |
import os
|
11 |
import base64
|
@@ -16,8 +15,8 @@ import codecs
|
|
16 |
import random
|
17 |
|
18 |
## Remember to set $env:OPENAI_API_KEY="keyhere"
|
19 |
-
openai.api_key = os.getenv("OPENAI_API_KEY")
|
20 |
-
|
21 |
def getAndParseQuickStart(text, count):
|
22 |
print("Asking AI for a character of " + text + " with trait count:")
|
23 |
print(count)
|
@@ -31,8 +30,8 @@ def getAndParseQuickStart(text, count):
|
|
31 |
Hates: descriptors (comma separated properties, at least {count} traits)
|
32 |
Attributes: descriptors (comma separated properties, at least {count} traits)
|
33 |
Clothes: descriptors (comma separated properties)
|
34 |
-
Sex: descriptor (choose from: Male, Female, or Other)
|
35 |
-
Sexuality: descriptor (choose from: Gay, Straight, Bi, or Asexual)
|
36 |
Age: descriptor (as an integer, no additional text)
|
37 |
Description: descriptor (3 sentences, do not repeat any previous information)
|
38 |
Personality_Summary: descriptor
|
@@ -102,7 +101,6 @@ def getAndParseQuickStart(text, count):
|
|
102 |
description = traits_dict.get('Description', '')
|
103 |
personalityProfile = traits_dict.get('Personality_Profile', '')
|
104 |
attributes = traits_dict.get('Attributes', '')
|
105 |
-
|
106 |
return [
|
107 |
raw,
|
108 |
charName,
|
@@ -170,20 +168,50 @@ def generateSpeakingStyle(text):
|
|
170 |
response.get('storytelling ability', '')
|
171 |
]
|
172 |
|
|
|
|
|
|
|
173 |
with gr.Blocks() as demo:
|
|
|
174 |
gr.Markdown(
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
def updateTraitCount(text):
|
188 |
numTraits = text
|
189 |
print (numTraits)
|
@@ -199,7 +227,6 @@ with gr.Blocks() as demo:
|
|
199 |
with gr.Row():
|
200 |
quickStart = gr.TextArea(label="Quick Start", info="Use AI to fill out all fields based on your description.")
|
201 |
generate = gr.Button("1. Generate Quick Start")
|
202 |
-
quickStartResult = gr.TextArea(label="result", interactive=False, show_copy_button=True)
|
203 |
|
204 |
with gr.Row():
|
205 |
with gr.Column(scale=1, min_width=600):
|
@@ -214,7 +241,7 @@ with gr.Blocks() as demo:
|
|
214 |
with gr.Row():
|
215 |
sex = gr.Dropdown(["Male", "Female", "Other"], label="Sex", interactive=True)
|
216 |
sexuality = gr.Textbox(label="Sexuality", interactive=True)
|
217 |
-
age = gr.Slider(1, 100, label="Age", info="Choose between 1 and 100", interactive=True, step=1.0)
|
218 |
description = gr.Textbox(label="Description", interactive=True)
|
219 |
attributes = gr.Textbox(label="Attributes", interactive=True)
|
220 |
with gr.Row():
|
@@ -298,7 +325,7 @@ with gr.Blocks() as demo:
|
|
298 |
|
299 |
med_secret_button.click(generateMedicalSecrets, inputs=[conditions_count], outputs=[med_secret])
|
300 |
generate.click(getAndParseQuickStart, inputs=[quickStart, trait_count], outputs=[
|
301 |
-
|
302 |
charName,
|
303 |
personality,
|
304 |
body,
|
@@ -312,6 +339,7 @@ with gr.Blocks() as demo:
|
|
312 |
attributes
|
313 |
])
|
314 |
createJSON = gr.Button("4. Create JSON")
|
|
|
315 |
def makePersonality(text):
|
316 |
print("Asking AI for a profile")
|
317 |
prompt = "Here are the details for you to analyze. Remember to return in the specified format: " + text
|
@@ -326,10 +354,10 @@ with gr.Blocks() as demo:
|
|
326 |
print(response_content)
|
327 |
return response_content
|
328 |
|
329 |
-
generatePersonality.click(makePersonality, inputs=[
|
330 |
|
331 |
|
332 |
-
genProfile.click(generateSpeakingStyle, inputs=[
|
333 |
formality,
|
334 |
pace,
|
335 |
rhythm,
|
@@ -359,8 +387,7 @@ with gr.Blocks() as demo:
|
|
359 |
cultural_references,
|
360 |
storytelling_ability
|
361 |
])
|
362 |
-
def createJSONfile(
|
363 |
-
charName,
|
364 |
personality,
|
365 |
body,
|
366 |
likes,
|
@@ -460,8 +487,7 @@ with gr.Blocks() as demo:
|
|
460 |
return cleaned_json_string
|
461 |
|
462 |
|
463 |
-
createJSON.click(createJSONfile, inputs=[
|
464 |
-
quickStartResult,
|
465 |
charName,
|
466 |
personality,
|
467 |
body,
|
|
|
5 |
from langchain.llms import OpenAI
|
6 |
from langchain.prompts import PromptTemplate
|
7 |
from langchain.chains import SequentialChain
|
|
|
8 |
import openai
|
9 |
import os
|
10 |
import base64
|
|
|
15 |
import random
|
16 |
|
17 |
## Remember to set $env:OPENAI_API_KEY="keyhere"
|
18 |
+
#openai.api_key = os.getenv("OPENAI_API_KEY")
|
19 |
+
openai.api_key = ""
|
20 |
def getAndParseQuickStart(text, count):
|
21 |
print("Asking AI for a character of " + text + " with trait count:")
|
22 |
print(count)
|
|
|
30 |
Hates: descriptors (comma separated properties, at least {count} traits)
|
31 |
Attributes: descriptors (comma separated properties, at least {count} traits)
|
32 |
Clothes: descriptors (comma separated properties)
|
33 |
+
Sex: descriptor (choose only from: Male, Female, or Other)
|
34 |
+
Sexuality: descriptor (choose only from: Gay, Straight, Bi, or Asexual. Default to Asexual)
|
35 |
Age: descriptor (as an integer, no additional text)
|
36 |
Description: descriptor (3 sentences, do not repeat any previous information)
|
37 |
Personality_Summary: descriptor
|
|
|
101 |
description = traits_dict.get('Description', '')
|
102 |
personalityProfile = traits_dict.get('Personality_Profile', '')
|
103 |
attributes = traits_dict.get('Attributes', '')
|
|
|
104 |
return [
|
105 |
raw,
|
106 |
charName,
|
|
|
168 |
response.get('storytelling ability', '')
|
169 |
]
|
170 |
|
171 |
+
def saveKey(text):
|
172 |
+
openai.api_key = text
|
173 |
+
|
174 |
with gr.Blocks() as demo:
|
175 |
+
rawQuickResults=gr.Textbox(visible=False)
|
176 |
gr.Markdown(
|
177 |
+
"""
|
178 |
+
# Character Maker v0.1 #
|
179 |
+
""")
|
180 |
+
with gr.Row():
|
181 |
+
myKey = gr.Text(label="OPENAI API KEY", info="must have gpt4 access (for now)")
|
182 |
+
keySave = gr.Button(value="Set")
|
183 |
+
keySave.click(saveKey, inputs=[myKey])
|
184 |
+
with gr.Row():
|
185 |
+
gr.Markdown(
|
186 |
+
"""
|
187 |
+
This is a very early prototype of a character generator/assistant.
|
188 |
+
The goal is to create a detailed but concise profile that can be used in chat programs and guide the AI in acting realistic.<br>
|
189 |
+
1. Adjust the traits count slider for how many traits you want the AI to return
|
190 |
+
2. Give a general description or starting point and click (1) Generate Quick Start (ex. "Winnie the Pooh but he is a cat")
|
191 |
+
3. Edit response fields as needed
|
192 |
+
4. Click (2) Analyze to create a Psychological Profile
|
193 |
+
5. Click (3) Generate Speaking Style
|
194 |
+
6. Edit any fields as you want
|
195 |
+
7. Click (4) Create JSON
|
196 |
+
""")
|
197 |
+
gr.Markdown(
|
198 |
+
"""
|
199 |
+
### Not Working Yet ###
|
200 |
+
- Scenario, Setting, Dialogue
|
201 |
+
- Secrets
|
202 |
+
|
203 |
+
### To Do ###
|
204 |
+
- Scenario and setting creator
|
205 |
+
- Chat sample creator and chooser
|
206 |
+
- Testable playground built-in
|
207 |
+
- Add grammar and spelling variable
|
208 |
+
- Have AI choose and expand on appropriate secrets
|
209 |
+
- Use Dall-E to generate profile pics
|
210 |
+
- Selection of JSON format to export as
|
211 |
+
- Add token count
|
212 |
+
- Add shorten function to send JSON to AI and ask to remove duplicate information
|
213 |
+
""")
|
214 |
+
numTraits = 8
|
215 |
def updateTraitCount(text):
|
216 |
numTraits = text
|
217 |
print (numTraits)
|
|
|
227 |
with gr.Row():
|
228 |
quickStart = gr.TextArea(label="Quick Start", info="Use AI to fill out all fields based on your description.")
|
229 |
generate = gr.Button("1. Generate Quick Start")
|
|
|
230 |
|
231 |
with gr.Row():
|
232 |
with gr.Column(scale=1, min_width=600):
|
|
|
241 |
with gr.Row():
|
242 |
sex = gr.Dropdown(["Male", "Female", "Other"], label="Sex", interactive=True)
|
243 |
sexuality = gr.Textbox(label="Sexuality", interactive=True)
|
244 |
+
age = gr.Slider(1, 100, label="Age", info="Choose between 1 and 100", interactive=True, step=1.0, value=21)
|
245 |
description = gr.Textbox(label="Description", interactive=True)
|
246 |
attributes = gr.Textbox(label="Attributes", interactive=True)
|
247 |
with gr.Row():
|
|
|
325 |
|
326 |
med_secret_button.click(generateMedicalSecrets, inputs=[conditions_count], outputs=[med_secret])
|
327 |
generate.click(getAndParseQuickStart, inputs=[quickStart, trait_count], outputs=[
|
328 |
+
rawQuickResults,
|
329 |
charName,
|
330 |
personality,
|
331 |
body,
|
|
|
339 |
attributes
|
340 |
])
|
341 |
createJSON = gr.Button("4. Create JSON")
|
342 |
+
quickStartResult = gr.JSON(label="result", interactive=False)
|
343 |
def makePersonality(text):
|
344 |
print("Asking AI for a profile")
|
345 |
prompt = "Here are the details for you to analyze. Remember to return in the specified format: " + text
|
|
|
354 |
print(response_content)
|
355 |
return response_content
|
356 |
|
357 |
+
generatePersonality.click(makePersonality, inputs=[rawQuickResults], outputs=[personalityProfile])
|
358 |
|
359 |
|
360 |
+
genProfile.click(generateSpeakingStyle, inputs=[rawQuickResults], outputs=[
|
361 |
formality,
|
362 |
pace,
|
363 |
rhythm,
|
|
|
387 |
cultural_references,
|
388 |
storytelling_ability
|
389 |
])
|
390 |
+
def createJSONfile(charName,
|
|
|
391 |
personality,
|
392 |
body,
|
393 |
likes,
|
|
|
487 |
return cleaned_json_string
|
488 |
|
489 |
|
490 |
+
createJSON.click(createJSONfile, scroll_to_output=True, inputs=[
|
|
|
491 |
charName,
|
492 |
personality,
|
493 |
body,
|
todo.txt
DELETED
@@ -1,6 +0,0 @@
|
|
1 |
-
- Scenario and setting creator
|
2 |
-
- Chat sample creator and chooser
|
3 |
-
- add Secrets (DM codes?)
|
4 |
-
- create and save a JSON
|
5 |
-
- Testable playground?
|
6 |
-
- Add grammar and spelling variable
|
|
|
|
|
|
|
|
|
|
|
|
|
|