amos1088 commited on
Commit
c3fd50e
·
1 Parent(s): 38e6a4b

test gradio

Browse files
Files changed (2) hide show
  1. app.py +51 -1
  2. requirements.txt +2 -1
app.py CHANGED
@@ -80,6 +80,39 @@ gif_pipe.load_lora_weights(lora_adapter_id, adapter_name="motion_lora")
80
 
81
 
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
  @spaces.GPU
85
  def generate_gif(prompt, reference_image, controlnet_conditioning_scale,num_frames):
@@ -126,6 +159,23 @@ This way, each frame represents a distinct scene, and there’s no redundancy be
126
 
127
  return "animation.gif"
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  # Set up Gradio interface
130
  interface = gr.Interface(
131
  fn=generate_gif,
@@ -137,7 +187,7 @@ interface = gr.Interface(
137
  gr.Slider(label="Number of frames", minimum=0, maximum=1.0, step=0.1, value=1.0),
138
 
139
  ],
140
- outputs="image",
141
  title="Image Generation with Stable Diffusion 3 medium and ControlNet",
142
  description="Generates an image based on a text prompt and a reference image using Stable Diffusion 3 medium with ControlNet."
143
 
 
80
 
81
 
82
 
83
+ @spaces.GPU
84
+ def generate_frames(prompt, reference_image, controlnet_conditioning_scale,num_frames):
85
+ massage_history = [{"role": "system", "content": """
86
+ You are a scene designer tasked with creating sparse frames of a video. You will be given a prompt describing the desired video, and your goal is to design only the key frames (sparse frames) that represent major changes in the scene. Do not include repetitive or similar scenes—only capture distinct moments.
87
+
88
+ Expected Format:
89
+ Return the response as a JSON object with the key "frames". The value should be a list of dictionaries, where each dictionary has:
90
+
91
+ "frame_index": an integer indicating the frame's position in the sequence.
92
+ "description": a brief description of the scene in this frame.
93
+ Example:
94
+ If given a prompt like "A sunset over a beach with waves crashing and a ship sailing by," your response should look like this:
95
+
96
+ ```json
97
+ {
98
+ "frames": [
99
+ {"frame_index": 0, "description": "Sunset over an empty beach, sky turning orange and pink"},
100
+ {"frame_index": 30, "description": "Waves gently crashing on the shore"},
101
+ {"frame_index": 60, "description": "A ship appears on the horizon, silhouetted by the sunset"},
102
+ {"frame_index": 90, "description": "Ship sailing closer, with waves becoming more dynamic"},
103
+ {"frame_index": 120, "description": "Sun dipping below the horizon, casting a golden glow over the water"}
104
+ ]
105
+ }
106
+ ```
107
+ This way, each frame represents a distinct scene, and there’s no redundancy between them."""},
108
+ {"role": "user", "content": f"give me the frames to generate a video with prompt : `{prompt}`"},]
109
+ frames = ask_gpt(massage_history,return_str=False)['frames']
110
+ conditioning_frames = []
111
+ controlnet_frame_indices =[]
112
+ for frame in frames:
113
+ conditioning_frames.append(generate_image(frame['description'], reference_image, controlnet_conditioning_scale))
114
+ controlnet_frame_indices.append(frame['frame_index'])
115
+ return conditioning_frames
116
 
117
  @spaces.GPU
118
  def generate_gif(prompt, reference_image, controlnet_conditioning_scale,num_frames):
 
159
 
160
  return "animation.gif"
161
 
162
+ # # Set up Gradio interface
163
+ # interface = gr.Interface(
164
+ # fn=generate_gif,
165
+ # inputs=[
166
+ # gr.Textbox(label="Prompt"),
167
+ # # gr.Image( type= "filepath",label="Reference Image (Style)"),
168
+ # gr.File(type="filepath",file_count="multiple",label="Reference Image (Style)"),
169
+ # gr.Slider(label="Control Net Conditioning Scale", minimum=0, maximum=1.0, step=0.1, value=1.0),
170
+ # gr.Slider(label="Number of frames", minimum=0, maximum=1.0, step=0.1, value=1.0),
171
+ #
172
+ # ],
173
+ # outputs="image",
174
+ # title="Image Generation with Stable Diffusion 3 medium and ControlNet",
175
+ # description="Generates an image based on a text prompt and a reference image using Stable Diffusion 3 medium with ControlNet."
176
+ #
177
+ # )
178
+
179
  # Set up Gradio interface
180
  interface = gr.Interface(
181
  fn=generate_gif,
 
187
  gr.Slider(label="Number of frames", minimum=0, maximum=1.0, step=0.1, value=1.0),
188
 
189
  ],
190
+ outputs="gallery",
191
  title="Image Generation with Stable Diffusion 3 medium and ControlNet",
192
  description="Generates an image based on a text prompt and a reference image using Stable Diffusion 3 medium with ControlNet."
193
 
requirements.txt CHANGED
@@ -6,4 +6,5 @@ gradio
6
  sentencepiece
7
  spaces
8
  pillow
9
- peft
 
 
6
  sentencepiece
7
  spaces
8
  pillow
9
+ peft
10
+ openai