File size: 2,294 Bytes
0cafc7b
 
 
 
5b75f42
0cafc7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a8f09ad
0cafc7b
 
a8f09ad
0cafc7b
 
67a7e49
 
0cafc7b
 
 
 
 
 
 
a8f09ad
0cafc7b
 
4192113
0cafc7b
 
 
9ddf6d4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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()