import gradio as gr from groq import Groq # Initialize the Groq client with your API key client = Groq(api_key="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") # Define the system message for the model system_message = { "role": "system", "content": "You are an experienced scriptwriter who generates engaging and creative movie content based on a given theme. Provide main characters, a storyline, and a movie script." } def generate_movie_content(theme): # Generate main characters and storyline using Groq setup_prompt = f"Generate main characters and a storyline for a movie with the theme: '{theme}'." response = client.chat(messages=[ system_message, {"role": "user", "content": setup_prompt} ]) setup = response["choices"][0]["message"]["content"] # Extract characters and storyline if "Main Characters:" in setup and "Storyline:" in setup: characters_start = setup.index("Main Characters:") + len("Main Characters:") storyline_start = setup.index("Storyline:") + len("Storyline:") characters = setup[characters_start:storyline_start].strip() storyline = setup[storyline_start:].strip() else: characters = "Unknown characters" storyline = "Unknown storyline" # Generate movie script using Groq script_prompt = ( f"Write a movie script based on the theme: '{theme}', with main characters: {characters}, and storyline: {storyline}." ) script_response = client.chat(messages=[ system_message, {"role": "user", "content": script_prompt} ]) script = script_response["choices"][0]["message"]["content"] return f"Main Characters:\n{characters}\n\nStoryline:\n{storyline}\n\nMovie Script:\n{script}" def main_interface(theme): return generate_movie_content(theme) # Gradio Interface title = "Movie Script Generator" description = "Generate movie scripts, characters, and storylines based on a single theme." demo = gr.Interface( fn=main_interface, inputs=[ gr.Textbox(label="Theme", placeholder="Enter the movie theme"), ], outputs=[ gr.Textbox(label="Generated Content", lines=20), ], title=title, description=description ) if __name__ == "__main__": demo.launch()