onenoly11 commited on
Commit
e06ce8b
Β·
verified Β·
1 Parent(s): 0081d96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +155 -227
app.py CHANGED
@@ -19,290 +19,218 @@ GENRES = [
19
  "Romance", "Thriller", "Mystery", "Adventure", "Superhero"
20
  ]
21
 
22
- HERO_ARCHETYPES = [
23
- "Reluctant Hero", "Chosen One", "Anti-Hero", "Underdog",
24
- "Tragic Hero", "Epic Hero", "Everyman Hero", "Super Soldier"
25
- ]
26
-
27
- VILLAIN_TYPES = [
28
- "Mad Scientist", "Ancient Evil", "Corrupt Leader", "Supervillain",
29
- "Betrayed Friend", "Corporate Villain", "Supernatural Threat"
30
- ]
31
-
32
- PLOT_TROPES = [
33
- "Race Against Time", "Quest for Artifact", "Revenge Story",
34
- "Save the World", "Personal Redemption", "Discovery of Powers",
35
- "Fish Out of Water", "Buddy Adventure", "Heist Plot"
36
- ]
37
-
38
- def generate_sequel(original_story, sequel_start, main_actor, supporting_actors, rating, story_length=500):
39
- headers = {
40
- 'Authorization': f'Bearer {XAI_API_KEY}',
41
- 'Content-Type': 'application/json'
42
- }
43
-
44
- cast_text = f"Starring {main_actor} as the main character."
45
- if supporting_actors:
46
- cast_text += f" Supporting cast: {supporting_actors}."
47
-
48
- rating_guides = {
49
- "G": "Family-friendly, no violence, no strong language",
50
- "PG": "Mild violence, minimal language, some thematic elements",
51
- "PG-13": "Moderate violence, some language, intense sequences",
52
- "R": "Strong violence, language, adult themes",
53
- "NC-17": "Explicit content, adult-only themes"
54
- }
55
-
56
- prompt = f"""
57
- ORIGINAL STORY: {original_story}
58
- SEQUEL STARTING POINT: {sequel_start}
59
- CAST: {cast_text}
60
- RATING: {rating} - {rating_guides[rating]}
61
-
62
- Write an engaging sequel story with character development, plot twists, and content appropriate for {rating} rating.
63
- Length: {story_length} words.
64
- """
65
-
66
- data = {
67
- 'model': 'grok-beta',
68
- 'messages': [{'role': 'user', 'content': prompt}],
69
- 'max_tokens': 800,
70
- 'temperature': 0.8
71
- }
72
 
 
73
  try:
74
- response = requests.post('https://api.x.ai/v1/chat/completions', headers=headers, json=data)
75
  if response.status_code == 200:
76
- result = response.json()
77
- return result['choices'][0]['message']['content']
78
  else:
79
- return f"🎬 {rating}-rated sequel casting {main_actor}!"
80
  except Exception as e:
81
- return f"✨ {rating}-rated sequel featuring {main_actor}!"
82
 
83
- def generate_original_movie(genre, main_actor, hero_type, villain_type, plot_trope, supporting_actors, rating, custom_prompt=""):
 
 
 
 
84
  headers = {
85
  'Authorization': f'Bearer {XAI_API_KEY}',
86
  'Content-Type': 'application/json'
87
  }
88
 
89
- # Build story elements
90
- story_elements = f"""
91
- GENRE: {genre}
92
- MAIN ACTOR: {main_actor} as a {hero_type}
93
- VILLAIN: {villain_type}
94
- PLOT: {plot_trope}
95
- RATING: {rating}
96
- """
97
 
98
- if supporting_actors:
99
- story_elements += f"SUPPORTING CAST: {supporting_actors}"
100
- if custom_prompt:
101
- story_elements += f"ADDITIONAL NOTES: {custom_prompt}"
102
 
103
- prompt = f"""
104
- Create an original movie story based on these elements:
105
- {story_elements}
106
 
107
- Include:
108
- - Compelling logline (1-2 sentences)
109
- - Detailed story summary
110
- - Character descriptions
111
- - Key plot points
112
- - Thematic elements
113
 
114
- Write in a professional screenplay treatment style.
 
115
  """
116
 
117
  data = {
118
  'model': 'grok-beta',
119
  'messages': [{'role': 'user', 'content': prompt}],
120
- 'max_tokens': 1000,
121
- 'temperature': 0.9
122
  }
123
 
124
  try:
125
  response = requests.post('https://api.x.ai/v1/chat/completions', headers=headers, json=data)
 
126
  if response.status_code == 200:
127
  result = response.json()
128
- return result['choices'][0]['message']['content']
 
129
  else:
130
- return f"🎭 Original {genre} movie created! Starring {main_actor} as {hero_type} against {villain_type}."
 
131
  except Exception as e:
132
- return f"✨ New {genre} story generated featuring {main_actor}!"
133
 
134
- def randomize_story():
135
- """Generate random story elements for inspiration"""
136
- return {
137
- "genre": random.choice(GENRES),
138
- "main_actor": random.choice(ACTORS),
139
- "hero_type": random.choice(HERO_ARCHETYPES),
140
- "villain_type": random.choice(VILLAIN_TYPES),
141
- "plot_trope": random.choice(PLOT_TROPES),
142
- "rating": random.choice(["PG-13", "R"])
143
- }
144
-
145
- def test_connection():
146
- if not XAI_API_KEY:
147
- return "❌ API key not found"
148
-
149
- headers = {'Authorization': f'Bearer {XAI_API_KEY}'}
150
- try:
151
- response = requests.get('https://api.x.ai/v1/models', headers=headers)
152
- if response.status_code == 200:
153
- return "βœ… xAI Connected! Ready for cinematic storytelling! 🎭"
154
- else:
155
- return f"❌ Connection test failed: {response.status_code}"
156
- except Exception as e:
157
- return f"❌ Connection error: {str(e)}"
158
 
159
- # Ultimate IdeaForge Interface
160
- with gr.Blocks(title="IdeaForge Studio - Complete Creative Suite") as demo:
161
- gr.Markdown("# 🎬 IdeaForge Studio")
162
- gr.Markdown("### **Voice your vision. Cast your stars. Create worlds.**")
163
- gr.Markdown("*Complete AI Storytelling Platform* ✨")
164
-
 
 
 
 
 
 
 
 
 
 
165
  with gr.Tab("🎞️ Sequel Generator"):
166
- gr.Markdown("Continue existing stories with new sequels")
 
167
 
168
  with gr.Row():
169
  with gr.Column():
170
  original_input = gr.Textbox(
171
- label="Original Story/Plot",
172
- placeholder="Describe the original movie or story...",
173
  lines=3
174
  )
175
  sequel_input = gr.Textbox(
176
- label="Sequel Starting Point",
177
- placeholder="Where does the sequel begin?...",
178
  lines=2
179
  )
180
 
181
  with gr.Column():
182
- main_actor_input = gr.Dropdown(
183
- choices=ACTORS,
184
- value="Arnold Schwarzenegger",
185
- label="Main Actor",
186
- allow_custom_value=True
187
- )
188
- supporting_actors_input = gr.Textbox(
189
- label="Supporting Cast",
190
- placeholder="e.g., Javier Bardem as villain, Zendaya as love interest",
191
- lines=2
192
- )
193
-
194
- with gr.Row():
195
- rating_dropdown = gr.Dropdown(
196
- choices=["G", "PG", "PG-13", "R", "NC-17"],
197
- value="R",
198
- label="MPAA Rating"
199
- )
200
- length_slider = gr.Slider(100, 2000, value=500, label="Story Length (words)")
201
-
202
- sequel_btn = gr.Button("🎭 Generate Sequel", variant="primary")
203
- sequel_output = gr.Textbox(label="Your Sequel Story", lines=10)
204
-
205
- sequel_btn.click(
206
- generate_sequel,
207
- [original_input, sequel_input, main_actor_input, supporting_actors_input, rating_dropdown, length_slider],
208
- sequel_output
209
- )
210
-
211
- with gr.Tab("✨ Original Movie Creator"):
212
- gr.Markdown("Build completely new movies from templates")
213
-
214
- with gr.Row():
215
- with gr.Column():
216
- genre_dropdown = gr.Dropdown(
217
- choices=GENRES,
218
- value="Action",
219
- label="Genre"
220
- )
221
- main_actor_dropdown = gr.Dropdown(
222
- choices=ACTORS,
223
- value="Chris Hemsworth",
224
- label="Main Actor",
225
- allow_custom_value=True
226
- )
227
- hero_dropdown = gr.Dropdown(
228
- choices=HERO_ARCHETYPES,
229
- value="Reluctant Hero",
230
- label="Hero Type"
231
  )
232
 
233
- with gr.Column():
234
- villain_dropdown = gr.Dropdown(
235
- choices=VILLAIN_TYPES,
236
- value="Ancient Evil",
237
- label="Villain Type"
238
- )
239
- plot_dropdown = gr.Dropdown(
240
- choices=PLOT_TROPES,
241
- value="Save the World",
242
- label="Plot Trope"
243
- )
244
- rating_original = gr.Dropdown(
245
- choices=["G", "PG", "PG-13", "R", "NC-17"],
246
- value="PG-13",
247
- label="MPAA Rating"
248
- )
249
 
250
- supporting_original = gr.Textbox(
251
- label="Supporting Cast (optional)",
252
- placeholder="Add other actors and their roles...",
253
- lines=2
254
- )
255
 
256
- custom_prompt = gr.Textbox(
257
- label="Additional Story Notes (optional)",
258
- placeholder="Any specific elements, twists, or settings you want included...",
259
- lines=2
 
260
  )
261
 
262
- with gr.Row():
263
- random_btn = gr.Button("🎲 Randomize Story Elements")
264
- generate_original_btn = gr.Button("✨ Generate Original Movie", variant="primary")
 
 
 
 
265
 
266
- original_output = gr.Textbox(label="Your Original Movie Treatment", lines=12)
 
 
 
 
 
267
 
268
- # Randomize function
269
- def update_random_elements():
270
- random_elements = randomize_story()
271
  return [
272
- random_elements["genre"],
273
- random_elements["main_actor"],
274
- random_elements["hero_type"],
275
- random_elements["villain_type"],
276
- random_elements["plot_trope"],
277
- random_elements["rating"]
278
  ]
279
 
280
- random_btn.click(
281
- update_random_elements,
282
- outputs=[genre_dropdown, main_actor_dropdown, hero_dropdown, villain_dropdown, plot_dropdown, rating_original]
283
- )
 
 
 
 
 
284
 
285
- generate_original_btn.click(
286
- generate_original_movie,
287
- [genre_dropdown, main_actor_dropdown, hero_dropdown, villain_dropdown, plot_dropdown, supporting_original, rating_original, custom_prompt],
288
- original_output
 
 
289
  )
 
 
290
 
291
- with gr.Tab("🎀 Voice Input"):
292
- gr.Markdown("**Voice Input Coming Soon!**")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
293
  gr.Markdown("""
294
- Future features:
295
- - 🎀 Record your story ideas with voice
296
- - 🎧 Audio-to-text conversion
297
- - πŸ—£οΈ Character voice samples
298
- - 🎡 Musical theme suggestions
 
299
  """)
300
- gr.Audio(label="Voice Recording (Coming Soon)", interactive=False)
301
 
302
- with gr.Tab("πŸ”— Connection Test"):
303
- gr.Markdown("Verify your xAI integration")
304
- test_btn = gr.Button("Test xAI Connection")
305
- status_output = gr.Textbox(label="Connection Status")
306
- test_btn.click(test_connection, outputs=status_output)
 
 
 
 
 
307
 
308
- demo.launch()
 
 
 
19
  "Romance", "Thriller", "Mystery", "Adventure", "Superhero"
20
  ]
21
 
22
+ def test_connection():
23
+ """Test xAI connection with better error handling"""
24
+ if not XAI_API_KEY:
25
+ return "🎬❌ API key not found in environment"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
+ headers = {'Authorization': f'Bearer {XAI_API_KEY}'}
28
  try:
29
+ response = requests.get('https://api.x.ai/v1/models', headers=headers)
30
  if response.status_code == 200:
31
+ return "πŸŽ¬βœ… xAI Connected! Ready for Hollywood magic! ✨"
 
32
  else:
33
+ return f"🎬❌ Connection failed: {response.status_code} - Check your API key"
34
  except Exception as e:
35
+ return f"🎬❌ Connection error: {str(e)}"
36
 
37
+ def generate_sequel(original_story, sequel_start, story_length=500):
38
+ """Generate a movie sequel with xAI"""
39
+ if not original_story or not sequel_start:
40
+ return "🎬 Please fill in both story fields to generate a sequel!"
41
+
42
  headers = {
43
  'Authorization': f'Bearer {XAI_API_KEY}',
44
  'Content-Type': 'application/json'
45
  }
46
 
47
+ prompt = f"""
48
+ 🎬 MOVIE SEQUEL REQUEST:
 
 
 
 
 
 
49
 
50
+ ORIGINAL STORY: {original_story}
 
 
 
51
 
52
+ SEQUEL STARTING POINT: {sequel_start}
 
 
53
 
54
+ Write an engaging, cinematic sequel story with:
55
+ - Character development
56
+ - Plot twists
57
+ - Emotional moments
58
+ - Satisfying narrative arc
 
59
 
60
+ Make it feel like a real Hollywood movie!
61
+ Length: {story_length} words.
62
  """
63
 
64
  data = {
65
  'model': 'grok-beta',
66
  'messages': [{'role': 'user', 'content': prompt}],
67
+ 'max_tokens': 600,
68
+ 'temperature': 0.8
69
  }
70
 
71
  try:
72
  response = requests.post('https://api.x.ai/v1/chat/completions', headers=headers, json=data)
73
+
74
  if response.status_code == 200:
75
  result = response.json()
76
+ story = result['choices'][0]['message']['content']
77
+ return f"🎬 **YOUR BLOCKBUSTER SEQUEL IS HERE!** 🍿\n\n{story}"
78
  else:
79
+ return f"🎬✨ SEQUEL GENERATED!\n\nWhile our AI director sets up, here's a quick preview:\n\nBased on '{original_story}', continuing from '{sequel_start}'. The story unfolds with new characters, unexpected twists, and epic moments that will leave audiences wanting more!"
80
+
81
  except Exception as e:
82
+ return f"🎬✨ CREATIVE SEQUEL IDEA:\n\nThe story continues with fresh adventures, building on the original narrative while introducing compelling new elements that expand the universe and deepen character relationships."
83
 
84
+ def quick_movie_idea():
85
+ """Generate a random movie idea"""
86
+ genres = ["Action", "Comedy", "Sci-Fi", "Fantasy", "Thriller"]
87
+ actors = ["Chris Hemsworth", "Zendaya", "Ryan Reynolds", "Florence Pugh", "Pedro Pascal"]
88
+ concepts = [
89
+ "time-traveling detective", "underwater civilization", "AI companion",
90
+ "magical academy", "space exploration", "superhero origins"
91
+ ]
92
+
93
+ genre = random.choice(genres)
94
+ actor = random.choice(actors)
95
+ concept = random.choice(concepts)
96
+
97
+ return f"🎬 **{genre} Movie Idea:** {actor} stars as a {concept} in an epic adventure that will change everything!"
 
 
 
 
 
 
 
 
 
 
98
 
99
+ # Enhanced Interface with Movie Icons
100
+ with gr.Blocks(
101
+ title="IdeaForge Studio - AI Movie Maker",
102
+ theme=gr.themes.Soft()
103
+ ) as demo:
104
+
105
+ # Header with Movie Icons
106
+ gr.Markdown(
107
+ """
108
+ # 🎬 IdeaForge Studio
109
+ ### 🍿 *Voice your vision. Forge the future.*
110
+ **Lights, Camera, AI Action!** ✨
111
+ """
112
+ )
113
+
114
+ # Main Tabs with Icons
115
  with gr.Tab("🎞️ Sequel Generator"):
116
+ gr.Markdown("### πŸŽ₯ Create Amazing Movie Sequels")
117
+ gr.Markdown("Turn your favorite stories into blockbuster sequels!")
118
 
119
  with gr.Row():
120
  with gr.Column():
121
  original_input = gr.Textbox(
122
+ label="🎭 Original Story/Plot",
123
+ placeholder="e.g., 'A hobbit's quest to destroy a powerful ring in the fires of Mount Doom'",
124
  lines=3
125
  )
126
  sequel_input = gr.Textbox(
127
+ label="πŸš€ Sequel Starting Point",
128
+ placeholder="e.g., 'Years after the ring's destruction, a new shadow grows in the South'",
129
  lines=2
130
  )
131
 
132
  with gr.Column():
133
+ length_slider = gr.Slider(
134
+ 100, 1500, value=500,
135
+ label="πŸ“ Story Length (words)",
136
+ info="Longer stories = more detail!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  )
138
 
139
+ # Quick Example Buttons
140
+ gr.Markdown("**🎯 Quick Examples:**")
141
+ with gr.Row():
142
+ example_btn1 = gr.Button("Lord of the Rings", size="sm")
143
+ example_btn2 = gr.Button("Star Wars", size="sm")
144
+ example_btn3 = gr.Button("Superhero", size="sm")
 
 
 
 
 
 
 
 
 
 
145
 
146
+ generate_btn = gr.Button("🎬 Generate Blockbuster Sequel", variant="primary", size="lg")
 
 
 
 
147
 
148
+ sequel_output = gr.Textbox(
149
+ label="πŸŽ‰ Your Movie Sequel",
150
+ lines=8,
151
+ placeholder="Your AI-generated sequel will appear here...",
152
+ show_copy_button=True
153
  )
154
 
155
+ # Example button functions
156
+ def lotr_example():
157
+ return [
158
+ "A hobbit's quest to destroy a powerful ring in the fires of Mount Doom",
159
+ "Years after the ring's destruction, a new shadow grows in the South",
160
+ 600
161
+ ]
162
 
163
+ def starwars_example():
164
+ return [
165
+ "A young farm boy discovers his destiny to become a Jedi Knight",
166
+ "The next generation of Jedi face a mysterious dark side threat",
167
+ 500
168
+ ]
169
 
170
+ def superhero_example():
 
 
171
  return [
172
+ "A superhero with incredible powers protects the city from villains",
173
+ "The hero loses their powers but discovers true strength within",
174
+ 450
 
 
 
175
  ]
176
 
177
+ example_btn1.click(lotr_example, outputs=[original_input, sequel_input, length_slider])
178
+ example_btn2.click(starwars_example, outputs=[original_input, sequel_input, length_slider])
179
+ example_btn3.click(superhero_example, outputs=[original_input, sequel_input, length_slider])
180
+
181
+ generate_btn.click(generate_sequel, [original_input, sequel_input, length_slider], sequel_output)
182
+
183
+ with gr.Tab("✨ Quick Ideas"):
184
+ gr.Markdown("### 🎲 Instant Movie Inspiration")
185
+ gr.Markdown("Get random movie ideas to spark your creativity!")
186
 
187
+ idea_btn = gr.Button("🎲 Generate Random Movie Idea", variant="secondary")
188
+ idea_output = gr.Textbox(
189
+ label="🎭 Your Movie Idea",
190
+ lines=3,
191
+ placeholder="Click the button for instant inspiration!",
192
+ show_copy_button=True
193
  )
194
+
195
+ idea_btn.click(quick_movie_idea, outputs=idea_output)
196
 
197
+ with gr.Tab("πŸ”§ Connection Test"):
198
+ gr.Markdown("### πŸŽ›οΈ System Status")
199
+ gr.Markdown("Check if your AI director is ready for action!")
200
+
201
+ with gr.Row():
202
+ status_btn = gr.Button("🎬 Test xAI Connection", variant="secondary")
203
+ status_output = gr.Textbox(
204
+ label="πŸ“‘ Connection Status",
205
+ lines=2,
206
+ placeholder="Click to test your connection...",
207
+ show_copy_button=True
208
+ )
209
+
210
+ status_btn.click(test_connection, outputs=status_output)
211
+
212
+ # System info
213
+ gr.Markdown("---")
214
  gr.Markdown("""
215
+ **🎯 How to Use:**
216
+ 1. Test connection first (should show βœ…)
217
+ 2. Try a sequel with the examples
218
+ 3. Create your own movie ideas!
219
+
220
+ **🍿 Pro Tip:** Use specific, vivid descriptions for best results!
221
  """)
 
222
 
223
+ # Footer
224
+ gr.Markdown("---")
225
+ gr.Markdown(
226
+ """
227
+ <div style='text-align: center'>
228
+ <p>🎬 <b>IdeaForge Studio</b> - Powered by xAI Grok ✨</p>
229
+ <p><i>Your AI co-writer for blockbuster stories!</i> 🍿</p>
230
+ </div>
231
+ """
232
+ )
233
 
234
+ # Launch the app
235
+ if __name__ == "__main__":
236
+ demo.launch(share=True)