ai-forever commited on
Commit
dffc412
1 Parent(s): 27539d2

add basic function beautify_prompt

Browse files
Files changed (1) hide show
  1. app.py +53 -3
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import subprocess
2
  subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
3
  # subprocess.run('pip install bitsandbytes', shell=True)
@@ -21,6 +22,8 @@ import uuid
21
  import random
22
  from huggingface_hub import hf_hub_download
23
 
 
 
24
  #gradio.helpers.CACHED_FOLDER = '/data/cache'
25
 
26
  # pipe = StableVideoDiffusionPipeline.from_pretrained(
@@ -134,7 +137,15 @@ with gr.Blocks() as demo:
134
  placeholder="Enter your prompt",
135
  container=False,
136
  )
137
- #TODO ? можно так принять входное значение
 
 
 
 
 
 
 
 
138
  resolution = gr.Dropdown(
139
  label="Video resolution",
140
  choices=["1:1", "9:16", "16:9", "1:2", "2:1"],
@@ -148,10 +159,49 @@ with gr.Blocks() as demo:
148
  # randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
149
  # motion_bucket_id = gr.Slider(label="Motion bucket id", info="Controls how much motion to add/remove from the image", value=127, minimum=1, maximum=255)
150
  # fps_id = gr.Slider(label="Frames per second", info="The length of your video in seconds will be 25/fps", value=6, minimum=5, maximum=30)
151
-
152
  # image.upload(fn=resize_image, inputs=image, outputs=image, queue=False)
153
- #TODO функция так принимает аргументы?
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  generate_btn.click(fn=sample, inputs=[prompt, resolution], outputs=[video], api_name="video")
 
 
 
 
 
155
  # gr.Examples(
156
  # examples=[
157
  # "images/blink_meme.png",
 
1
+ # исправленная версия (чтобы не потерялась)
2
  import subprocess
3
  subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
4
  # subprocess.run('pip install bitsandbytes', shell=True)
 
22
  import random
23
  from huggingface_hub import hf_hub_download
24
 
25
+ from src.gigachat import giga_generate
26
+
27
  #gradio.helpers.CACHED_FOLDER = '/data/cache'
28
 
29
  # pipe = StableVideoDiffusionPipeline.from_pretrained(
 
137
  placeholder="Enter your prompt",
138
  container=False,
139
  )
140
+ #TODO нужен здесь Row или нет, можно сразу с Markdown
141
+ with gr.Row():
142
+ #TODO давать ссылку на гигачат?
143
+ #TODO заменить текст)
144
+ gr.Markdown(
145
+ "✨Upon pressing the enhanced prompt button, we will use [GigaChat Model](https://github.com/THUDM/GLM-4) to polish the prompt and overwrite the original one."
146
+ )
147
+ enhance_button = gr.Button("✨ Enhance Prompt(Optional)")
148
+
149
  resolution = gr.Dropdown(
150
  label="Video resolution",
151
  choices=["1:1", "9:16", "16:9", "1:2", "2:1"],
 
159
  # randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
160
  # motion_bucket_id = gr.Slider(label="Motion bucket id", info="Controls how much motion to add/remove from the image", value=127, minimum=1, maximum=255)
161
  # fps_id = gr.Slider(label="Frames per second", info="The length of your video in seconds will be 25/fps", value=6, minimum=5, maximum=30)
162
+
163
  # image.upload(fn=resize_image, inputs=image, outputs=image, queue=False)
164
+
165
+ #TODO изменить под гигачат
166
+ def beautify_prompt(prompt: str, retry_times: int = 3) -> str:
167
+ prompt = giga_generate(prompt)
168
+
169
+
170
+ # if not os.environ.get("OPENAI_API_KEY"):
171
+ # return prompt
172
+ # client = OpenAI()
173
+ # text = prompt.strip()
174
+
175
+ # for i in range(retry_times):
176
+ # response = client.chat.completions.create(
177
+ # messages=[
178
+ # {"role": "system", "content": sys_prompt},
179
+ # {
180
+ # "role": "user",
181
+ # "content": 'Create an imaginative video descriptive caption or modify an earlier caption for the user input : "a girl is on the beach"',
182
+ # },
183
+ # {
184
+ # "role": "assistant",
185
+ # "content": "A radiant woman stands on a deserted beach, arms outstretched, wearing a beige trench coat, white blouse, light blue jeans, and chic boots, against a backdrop of soft sky and sea. Moments later, she is seen mid-twirl, arms exuberant, with the lighting suggesting dawn or dusk. Then, she runs along the beach, her attire complemented by an off-white scarf and black ankle boots, the tranquil sea behind her. Finally, she holds a paper airplane, her pose reflecting joy and freedom, with the ocean's gentle waves and the sky's soft pastel hues enhancing the serene ambiance.",
186
+ # }
187
+ # ],
188
+ # model="glm-4-plus",
189
+ # temperature=0.01,
190
+ # top_p=0.7,
191
+ # stream=False,
192
+ # max_tokens=200,
193
+ # )
194
+ # if response.choices:
195
+ # return response.choices[0].message.content
196
+ return prompt
197
+
198
+
199
  generate_btn.click(fn=sample, inputs=[prompt, resolution], outputs=[video], api_name="video")
200
+ #TODO
201
+ def enhance_prompt_func(prompt):
202
+ return beautify_prompt(prompt, retry_times=1)
203
+ #TODO
204
+ enhance_button.click(enhance_prompt_func, inputs=[prompt], outputs=[prompt])
205
  # gr.Examples(
206
  # examples=[
207
  # "images/blink_meme.png",