awacke1 commited on
Commit
ba9176f
ยท
verified ยท
1 Parent(s): 591223b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -38
app.py CHANGED
@@ -4,28 +4,23 @@ import time
4
  from datetime import datetime
5
  import tempfile
6
  import os
7
- from moviepy.editor import ImageClip, concatenate_videoclips
8
- from gradio_client import Client
9
- from PIL import Image
10
  import edge_tts
11
  import asyncio
12
  import warnings
13
- import numpy as np
14
 
15
  warnings.filterwarnings('ignore')
16
 
17
- # Initialize Gradio clients with public demo spaces
18
  def initialize_clients():
19
  try:
20
- # Use a simpler public demo space
21
- image_client = Client("awacke1/Arxiv-Paper-Search-And-QA-RAG-Pattern")
22
- return image_client
23
  except Exception as e:
24
- print(f"Error initializing clients: {str(e)}")
25
  return None
26
 
27
  if gr.NO_RELOAD:
28
- # Initialize client in NO_RELOAD block to prevent multiple initializations
29
  CLIENT = initialize_clients()
30
 
31
  STORY_GENRES = [
@@ -40,10 +35,10 @@ STORY_GENRES = [
40
  ]
41
 
42
  STORY_STRUCTURES = {
43
- "Three Act": "Setup (Introduction, Inciting Incident) -> Confrontation (Rising Action, Climax) -> Resolution (Falling Action, Conclusion)",
44
- "Hero's Journey": "Ordinary World -> Call to Adventure -> Trials -> Transformation -> Return",
45
  "Five Act": "Exposition -> Rising Action -> Climax -> Falling Action -> Resolution",
46
- "Seven Point": "Hook -> Plot Turn 1 -> Pinch Point 1 -> Midpoint -> Pinch Point 2 -> Plot Turn 2 -> Resolution"
47
  }
48
 
49
  async def generate_speech(text, voice="en-US-AriaNeural"):
@@ -85,22 +80,6 @@ def generate_story(prompt, model_choice):
85
  except Exception as e:
86
  return f"Error generating story: {str(e)}"
87
 
88
- def process_story(story_text, num_scenes=5):
89
- """Break story into scenes for visualization"""
90
- if not story_text:
91
- return []
92
-
93
- sentences = story_text.split('.')
94
- scenes = []
95
- scene_length = max(1, len(sentences) // num_scenes)
96
-
97
- for i in range(0, len(sentences), scene_length):
98
- scene = '. '.join(sentences[i:i+scene_length]).strip()
99
- if scene:
100
- scenes.append(scene)
101
-
102
- return scenes[:num_scenes]
103
-
104
  def story_generator_interface(prompt, genre, structure, model_choice, num_scenes, words_per_scene):
105
  """Main story generation and multimedia creation function"""
106
  try:
@@ -110,20 +89,23 @@ def story_generator_interface(prompt, genre, structure, model_choice, num_scenes
110
  # Generate story
111
  story = generate_story(story_prompt, model_choice)
112
  if story.startswith("Error"):
113
- return story, None, None, None
114
 
115
  # Generate speech
116
  audio_path = asyncio.run(generate_speech(story))
117
 
118
- return story, None, audio_path, None
119
 
120
  except Exception as e:
121
  error_msg = f"An error occurred: {str(e)}"
122
- return error_msg, None, None, None
123
 
124
  # Create Gradio interface
125
  with gr.Blocks(title="AI Story Generator") as demo:
126
- gr.Markdown("# ๐ŸŽญ AI Story Generator")
 
 
 
127
 
128
  with gr.Row():
129
  with gr.Column():
@@ -168,17 +150,31 @@ with gr.Blocks(title="AI Story Generator") as demo:
168
  story_output = gr.Textbox(
169
  label="Generated Story",
170
  lines=10,
171
- interactive=False # Changed from readonly to interactive=False
172
  )
173
 
174
  with gr.Row():
175
- audio_output = gr.Audio(label="Story Narration")
 
 
 
176
 
 
177
  generate_btn.click(
178
  fn=story_generator_interface,
179
- inputs=[prompt_input, genre_input, structure_input, model_choice, num_scenes, words_per_scene],
180
- outputs=[story_output, None, audio_output, None] # Set image and video outputs to None for now
 
 
 
 
 
 
 
 
 
 
181
  )
182
 
183
  if __name__ == "__main__":
184
- demo.launch(reload=True)
 
4
  from datetime import datetime
5
  import tempfile
6
  import os
 
 
 
7
  import edge_tts
8
  import asyncio
9
  import warnings
10
+ from gradio_client import Client
11
 
12
  warnings.filterwarnings('ignore')
13
 
14
+ # Initialize Gradio client
15
  def initialize_clients():
16
  try:
17
+ client = Client("awacke1/Arxiv-Paper-Search-And-QA-RAG-Pattern")
18
+ return client
 
19
  except Exception as e:
20
+ print(f"Error initializing client: {str(e)}")
21
  return None
22
 
23
  if gr.NO_RELOAD:
 
24
  CLIENT = initialize_clients()
25
 
26
  STORY_GENRES = [
 
35
  ]
36
 
37
  STORY_STRUCTURES = {
38
+ "Three Act": "Setup -> Confrontation -> Resolution",
39
+ "Hero's Journey": "Ordinary World -> Call to Adventure -> Trials -> Return",
40
  "Five Act": "Exposition -> Rising Action -> Climax -> Falling Action -> Resolution",
41
+ "Seven Point": "Hook -> Plot Turn 1 -> Pinch Point 1 -> Midpoint -> Plot Turn 2 -> Resolution"
42
  }
43
 
44
  async def generate_speech(text, voice="en-US-AriaNeural"):
 
80
  except Exception as e:
81
  return f"Error generating story: {str(e)}"
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  def story_generator_interface(prompt, genre, structure, model_choice, num_scenes, words_per_scene):
84
  """Main story generation and multimedia creation function"""
85
  try:
 
89
  # Generate story
90
  story = generate_story(story_prompt, model_choice)
91
  if story.startswith("Error"):
92
+ return story, None
93
 
94
  # Generate speech
95
  audio_path = asyncio.run(generate_speech(story))
96
 
97
+ return story, audio_path
98
 
99
  except Exception as e:
100
  error_msg = f"An error occurred: {str(e)}"
101
+ return error_msg, None
102
 
103
  # Create Gradio interface
104
  with gr.Blocks(title="AI Story Generator") as demo:
105
+ gr.Markdown("""
106
+ # ๐ŸŽญ AI Story Generator
107
+ Generate creative stories with AI and listen to them!
108
+ """)
109
 
110
  with gr.Row():
111
  with gr.Column():
 
150
  story_output = gr.Textbox(
151
  label="Generated Story",
152
  lines=10,
153
+ interactive=False
154
  )
155
 
156
  with gr.Row():
157
+ audio_output = gr.Audio(
158
+ label="Story Narration",
159
+ type="filepath"
160
+ )
161
 
162
+ # Fixed the click event outputs
163
  generate_btn.click(
164
  fn=story_generator_interface,
165
+ inputs=[
166
+ prompt_input,
167
+ genre_input,
168
+ structure_input,
169
+ model_choice,
170
+ num_scenes,
171
+ words_per_scene
172
+ ],
173
+ outputs=[
174
+ story_output,
175
+ audio_output
176
+ ]
177
  )
178
 
179
  if __name__ == "__main__":
180
+ demo.launch(reload=True)