andreinigo commited on
Commit
8b6447f
1 Parent(s): fc4c4d5

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +47 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import openai
3
+ import os
4
+
5
+ openai.api_key = "sk-"+os.environ['OPENAI_API_KEY']
6
+
7
+
8
+ def generate_characters(input_description):
9
+ response = openai.ChatCompletion.create(
10
+ model="gpt-3.5-turbo",
11
+ messages=[
12
+ {"role": "system", "content": "Write the characters for a given story using the same language as the user. The only part that should be in English is the separators between characters, which are <character>, <description>, <stop> and <end>."},
13
+ {"role": "user", "content": "A science-fiction fantasy about a naive but ambitious farm boy from a backwater desert who discovers powers he never knew he had when he teams up with a feisty princess, a mercenary space pilot and an old wizard warrior to lead a ragtag rebellion against the sinister forces of the evil Galactic Empire."},
14
+ {"role": "assistant", "content": "<character>Luke Skywalker <description>Luke Skywalker is the hero. A naive farm boy, he will discover special powers under the guidance of mentor Ben Kenobi.<stop>\n<character>Ben Kenobi <description>Ben Kenobi is the mentor figure. A recluse Jedi warrior, he will take Luke Skywalker as apprentice.<stop>\n<character>Darth Vader <description>Darth Vader is the antagonist. As a commander of the evil Galactic Empire, he controls space station The Death Star.<stop>\n<character>Princess Leia <description>Princess Leia is a feisty and brave leader of the Rebellion. She holds the plans of the Death Star. She will become Luke鈥檚 friend.<stop>\n<character>Han Solo <description>Han Solo is a brash mercenary space pilot of the Millenium Falcon and a friend of Chebacca. He will take Luke on his spaceship.<stop>\n<character>Chewbacca <description>Chewbacca is a furry and trustful monster. He is a friend of Han Solo and a copilot on the Millemium Falcon.<stop>\n<end>"},
15
+ {"role": "user", "content": input_description}
16
+ ],
17
+ temperature=0.6
18
+ )
19
+ character_names = []
20
+ character_descriptions = []
21
+ content_split = response.choices[0].message.content.split("<stop>")
22
+ for i in range(0, len(content_split) - 1):
23
+ if content_split[i] == "<end>":
24
+ break
25
+ character_parts = content_split[i].split("<description>")
26
+ if len(character_parts) >= 2:
27
+ character_names.append(character_parts[0].strip())
28
+ character_descriptions.append(character_parts[1].strip())
29
+ else:
30
+ character_names.append(character_parts[0].strip())
31
+ # Add an empty description if not available
32
+ character_descriptions.append("")
33
+ return character_names, character_descriptions
34
+
35
+
36
+ demo = gr.Interface(
37
+ fn=generate_characters,
38
+ # input
39
+ inputs=gr.Textbox(label="Descripci贸n de la historia"),
40
+ # output
41
+ outputs=[
42
+ # title
43
+ gr.Textbox(label="Personajes")],
44
+ title="Dramatron 2.0",
45
+ description="Escribe la descripci贸n de la historia para la cu谩l quieres generar los personajes.")
46
+
47
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ backoff
2
+ openai