benjamin-paine commited on
Commit
badc904
Β·
verified Β·
1 Parent(s): cf0849b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -9
app.py CHANGED
@@ -2,22 +2,33 @@ import gradio as gr
2
  import spaces
3
  import torch
4
  import torch.amp as amp
5
- from transformers import pipeline
6
 
7
- repo_id = "appmana/Cosmos-1.0-Prompt-Upsampler-12B-Text2World-hf"
8
- upsampler = pipeline("text-generation", repo_id, torch_dtype=torch.bfloat16)
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  @spaces.GPU
11
  def upsample(prompt):
12
- return upsampler(
13
- [{"role": "user", "content": f"Upsample the short caption to a long caption: {prompt}"}],
14
- do_sample=False,
15
- max_new_tokens=512
16
- )[0]["generated_text"][-1]["content"]
 
17
 
18
  demo = gr.Interface(
19
  title="NVIDIA Cosmos 🌌 Prompt Upsampler",
20
- description="""Upsample prompts using NVIDIA's 12B Cosmos model, based on Mistral NeMo 12B. This space uses the HuggingFace Transformers version at bfloat16 precision.
21
 
22
  [[cosmos]](https://huggingface.co/nvidia/Cosmos-1.0-Prompt-Upsampler-12B-Text2World) [[transformers]](https://huggingface.co/appmana/Cosmos-1.0-Prompt-Upsampler-12B-Text2World-hf) [[gguf]](https://huggingface.co/mradermacher/Cosmos-1.0-Prompt-Upsampler-12B-Text2World-hf-GGUF)""",
23
  fn=upsample,
 
2
  import spaces
3
  import torch
4
  import torch.amp as amp
 
5
 
6
+ from huggingface_hub import hf_hub_download
7
+ from llama_cpp import Llama
8
+
9
+ model = hf_hub_download(
10
+ "mradermacher/Cosmos-1.0-Prompt-Upsampler-12B-Text2World-hf-GGUF",
11
+ filename="Cosmos-1.0-Prompt-Upsampler-12B-Text2World-hf.Q8_0.gguf",
12
+ )
13
+ llama = Llama(
14
+ model,
15
+ n_gpu_layers=-1,
16
+ n_ctx=2048,
17
+ verbose=False
18
+ )
19
 
20
  @spaces.GPU
21
  def upsample(prompt):
22
+ completion = llama.create_chat_completion(
23
+ messages=[{"role": "user", "content": f"Upsample the short caption to a long caption: {prompt}"}],
24
+ max_tokens=512,
25
+ )
26
+ response = completion["choices"][0]["message"]["content"]
27
+ return response
28
 
29
  demo = gr.Interface(
30
  title="NVIDIA Cosmos 🌌 Prompt Upsampler",
31
+ description="""Upsample prompts using NVIDIA's 12B Cosmos model, based on Mistral NeMo 12B. This space uses llama.cpp with the Q8-0 quantized GGUF checkpoint.
32
 
33
  [[cosmos]](https://huggingface.co/nvidia/Cosmos-1.0-Prompt-Upsampler-12B-Text2World) [[transformers]](https://huggingface.co/appmana/Cosmos-1.0-Prompt-Upsampler-12B-Text2World-hf) [[gguf]](https://huggingface.co/mradermacher/Cosmos-1.0-Prompt-Upsampler-12B-Text2World-hf-GGUF)""",
34
  fn=upsample,