Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,7 @@ from mpl_toolkits.mplot3d import Axes3D
|
|
11 |
import io
|
12 |
import base64
|
13 |
import os
|
|
|
14 |
|
15 |
# Initialize text generation model (GPT-2)
|
16 |
tokenizer = AutoTokenizer.from_pretrained("gpt2")
|
@@ -31,37 +32,48 @@ def generate_speech(text):
|
|
31 |
tts.tts_to_file(text=text, file_path=output_path)
|
32 |
return output_path
|
33 |
|
34 |
-
# Function to
|
35 |
-
def
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
line.set_data(data[:2, :num])
|
38 |
line.set_3d_properties(data[2, :num])
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
fig = plt.figure()
|
42 |
ax = fig.add_subplot(111, projection='3d')
|
43 |
|
44 |
-
# Generate a
|
45 |
-
t = np.linspace(0,
|
46 |
-
x = np.sin(t)
|
47 |
-
y = np.cos(t)
|
48 |
z = t/10
|
49 |
|
50 |
data = np.array([x, y, z])
|
51 |
line, = ax.plot(data[0, 0:1], data[1, 0:1], data[2, 0:1])
|
52 |
|
53 |
# Setting the axes properties
|
54 |
-
ax.set_xlim3d([-
|
55 |
ax.set_xlabel('X')
|
56 |
-
ax.set_ylim3d([-
|
57 |
ax.set_ylabel('Y')
|
58 |
-
ax.set_zlim3d([0.0,
|
59 |
ax.set_zlabel('Z')
|
60 |
|
61 |
-
|
62 |
-
ax.text2D(0.05, 0.95, text[:50], transform=ax.transAxes)
|
63 |
-
|
64 |
-
ani = animation.FuncAnimation(fig, update_point, frames=100, fargs=(data, line), interval=100, blit=False)
|
65 |
|
66 |
# Save animation as gif
|
67 |
ani.save('character_animation.gif', writer='pillow')
|
@@ -84,7 +96,7 @@ def generate_kids_music_animation(theme):
|
|
84 |
|
85 |
# Gradio Interface
|
86 |
with gr.Blocks() as app:
|
87 |
-
gr.Markdown("##
|
88 |
|
89 |
with gr.Tab("Comedy Animation"):
|
90 |
comedy_prompt = gr.Textbox(label="Enter comedy prompt")
|
|
|
11 |
import io
|
12 |
import base64
|
13 |
import os
|
14 |
+
import re
|
15 |
|
16 |
# Initialize text generation model (GPT-2)
|
17 |
tokenizer = AutoTokenizer.from_pretrained("gpt2")
|
|
|
32 |
tts.tts_to_file(text=text, file_path=output_path)
|
33 |
return output_path
|
34 |
|
35 |
+
# Function to extract keywords from the script
|
36 |
+
def extract_keywords(script):
|
37 |
+
# Simple keyword extraction (you might want to use a more sophisticated method)
|
38 |
+
keywords = re.findall(r'\b\w+\b', script.lower())
|
39 |
+
return list(set(keywords))
|
40 |
+
|
41 |
+
# Function to create a character animation based on script keywords
|
42 |
+
def create_character_animation(script):
|
43 |
+
keywords = extract_keywords(script)
|
44 |
+
|
45 |
+
def update_point(num, data, line, ax, keywords):
|
46 |
line.set_data(data[:2, :num])
|
47 |
line.set_3d_properties(data[2, :num])
|
48 |
+
|
49 |
+
# Update text with cycling keywords
|
50 |
+
keyword = keywords[num % len(keywords)]
|
51 |
+
ax.texts.clear()
|
52 |
+
ax.text2D(0.05, 0.95, keyword, transform=ax.transAxes)
|
53 |
+
|
54 |
+
return line,
|
55 |
|
56 |
fig = plt.figure()
|
57 |
ax = fig.add_subplot(111, projection='3d')
|
58 |
|
59 |
+
# Generate a 3D path influenced by the number of keywords
|
60 |
+
t = np.linspace(0, 2*np.pi*len(keywords)/10, 100)
|
61 |
+
x = np.sin(t) * (1 + len(keywords)/20)
|
62 |
+
y = np.cos(t) * (1 + len(keywords)/20)
|
63 |
z = t/10
|
64 |
|
65 |
data = np.array([x, y, z])
|
66 |
line, = ax.plot(data[0, 0:1], data[1, 0:1], data[2, 0:1])
|
67 |
|
68 |
# Setting the axes properties
|
69 |
+
ax.set_xlim3d([-2.0, 2.0])
|
70 |
ax.set_xlabel('X')
|
71 |
+
ax.set_ylim3d([-2.0, 2.0])
|
72 |
ax.set_ylabel('Y')
|
73 |
+
ax.set_zlim3d([0.0, 4.0])
|
74 |
ax.set_zlabel('Z')
|
75 |
|
76 |
+
ani = animation.FuncAnimation(fig, update_point, frames=100, fargs=(data, line, ax, keywords), interval=100, blit=False)
|
|
|
|
|
|
|
77 |
|
78 |
# Save animation as gif
|
79 |
ani.save('character_animation.gif', writer='pillow')
|
|
|
96 |
|
97 |
# Gradio Interface
|
98 |
with gr.Blocks() as app:
|
99 |
+
gr.Markdown("## Script-based Character Animation Generator")
|
100 |
|
101 |
with gr.Tab("Comedy Animation"):
|
102 |
comedy_prompt = gr.Textbox(label="Enter comedy prompt")
|