benjamin-paine commited on
Commit
37cb1ca
Β·
verified Β·
1 Parent(s): b7d72bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -5
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import gradio as gr
2
  import spaces
3
  import torch
@@ -11,6 +12,12 @@ model = hf_hub_download(
11
  )
12
  llama = None
13
 
 
 
 
 
 
 
14
  @spaces.GPU
15
  def upsample(prompt):
16
  global llama
@@ -26,7 +33,8 @@ def upsample(prompt):
26
  max_tokens=512,
27
  )
28
  response = completion["choices"][0]["message"]["content"]
29
- return response
 
30
 
31
  demo = gr.Interface(
32
  title="NVIDIA Cosmos 🌌 Prompt Upsampler",
@@ -38,9 +46,17 @@ demo = gr.Interface(
38
  label="Prompt",
39
  value="A dog playing with a ball."
40
  ),
41
- outputs=gr.Text(
42
- label="Upsampled Prompt",
43
- interactive=False
44
- )
 
 
 
 
 
 
 
 
45
  )
46
  demo.launch()
 
1
+ import re
2
  import gradio as gr
3
  import spaces
4
  import torch
 
12
  )
13
  llama = None
14
 
15
+ def trim_upsampled_caption(prompt):
16
+ try:
17
+ return re.match(r".*[\"β€œ](.*)[\"”]", prompt).group(1)
18
+ except:
19
+ return prompt
20
+
21
  @spaces.GPU
22
  def upsample(prompt):
23
  global llama
 
33
  max_tokens=512,
34
  )
35
  response = completion["choices"][0]["message"]["content"]
36
+ trimmed = trim_upsampled_caption(response)
37
+ return response, trimmed
38
 
39
  demo = gr.Interface(
40
  title="NVIDIA Cosmos 🌌 Prompt Upsampler",
 
46
  label="Prompt",
47
  value="A dog playing with a ball."
48
  ),
49
+ outputs=[
50
+ gr.Text(
51
+ label="Trimmed Upsampled Prompt",
52
+ interactive=False,
53
+ value="In a sun-drenched backyard, a playful golden retriever bounds joyfully across the lush green grass, its tail wagging with excitement. The dog, adorned with a vibrant blue collar, is captivated by a bright yellow ball, which it cradles gently in its mouth, its eyes sparkling with anticipation. The camera, held steady, captures the dog's animated expressions as it trots towards the viewer, its movements fluid and graceful. The scene is bathed in warm, golden-hour light, enhancing the vibrant colors of the dog's fur and the lush surroundings. As the dog playfully tosses the ball into the air, it leaps with enthusiasm, showcasing its agility and playful spirit. The serene backdrop of a white fence and a distant tree line frames this heartwarming moment, inviting viewers to share in the simple joy of a dog's playful antics."
54
+ ),
55
+ gr.Text(
56
+ label="Raw Upsampled Prompt",
57
+ interactive=False,
58
+ value="β€œIn a sun-drenched backyard, a playful golden retriever bounds joyfully across the lush green grass, its tail wagging with excitement. The dog, adorned with a vibrant blue collar, is captivated by a bright yellow ball, which it cradles gently in its mouth, its eyes sparkling with anticipation. The camera, held steady, captures the dog's animated expressions as it trots towards the viewer, its movements fluid and graceful. The scene is bathed in warm, golden-hour light, enhancing the vibrant colors of the dog's fur and the lush surroundings. As the dog playfully tosses the ball into the air, it leaps with enthusiasm, showcasing its agility and playful spirit. The serene backdrop of a white fence and a distant tree line frames this heartwarming moment, inviting viewers to share in the simple joy of a dog's playful antics.”"
59
+ )
60
+ ]
61
  )
62
  demo.launch()