MohamedRashad commited on
Commit
862ff54
·
verified ·
1 Parent(s): ebe58c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -17
app.py CHANGED
@@ -6,6 +6,7 @@ import torch
6
  from diffusers import FluxPipeline, AutoencoderKL
7
  from live_preview_helpers import flux_pipe_call_that_returns_an_iterable_of_images
8
  import spaces
 
9
 
10
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
11
 
@@ -17,9 +18,12 @@ good_vae = AutoencoderKL.from_pretrained("black-forest-labs/FLUX.1-dev", subfold
17
  # pipe.to(torch.float16)
18
  pipe.flux_pipe_call_that_returns_an_iterable_of_images = flux_pipe_call_that_returns_an_iterable_of_images.__get__(pipe)
19
 
20
- llm_client = Client("Qwen/Qwen2.5-72B-Instruct")
21
- # t2i_client = Client("black-forest-labs/FLUX.1-dev")
22
- # t2i_client = Client("black-forest-labs/FLUX.1-schnell")
 
 
 
23
 
24
  ds = load_dataset("MohamedRashad/FinePersonas-Lite", split="train")
25
 
@@ -44,13 +48,16 @@ Don't write anything else except the character description in json format and do
44
  world_description_prompt = "Generate a unique and random world description (Don't Write anything else except the world description)."
45
 
46
  def get_random_world_description():
47
- result = llm_client.predict(
48
- query=world_description_prompt,
49
- history=[],
50
- system="You are Qwen, created by Alibaba Cloud. You are a helpful assistant.",
51
- api_name="/model_chat",
 
 
 
52
  )
53
- return result[1][0][-1]
54
 
55
  def get_random_persona_description():
56
  return ds.shuffle().select([100])[0]["persona"]
@@ -70,15 +77,18 @@ def infer_flux(character_json):
70
  yield image
71
 
72
  def generate_character(world_description, persona_description, progress=gr.Progress(track_tqdm=True)):
73
- result = llm_client.predict(
74
- query=prompt_template.format(
75
- persona_description=persona_description, world_description=world_description
76
- ),
77
- history=[],
78
- system="You are Qwen, created by Alibaba Cloud. You are a helpful assistant.",
79
- api_name="/model_chat",
 
 
 
80
  )
81
- output = json.loads(result[1][0][-1])
82
  return output
83
 
84
  app_description = """
 
6
  from diffusers import FluxPipeline, AutoencoderKL
7
  from live_preview_helpers import flux_pipe_call_that_returns_an_iterable_of_images
8
  import spaces
9
+ from huggingface_hub import InferenceClient
10
 
11
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
12
 
 
18
  # pipe.to(torch.float16)
19
  pipe.flux_pipe_call_that_returns_an_iterable_of_images = flux_pipe_call_that_returns_an_iterable_of_images.__get__(pipe)
20
 
21
+ llm_client = InferenceClient(
22
+ provider="fireworks-ai",
23
+ api_key=os.environ["HF_TOKEN"],
24
+ )
25
+
26
+ completion = client
27
 
28
  ds = load_dataset("MohamedRashad/FinePersonas-Lite", split="train")
29
 
 
48
  world_description_prompt = "Generate a unique and random world description (Don't Write anything else except the world description)."
49
 
50
  def get_random_world_description():
51
+ result = llm_client.chat.completions.create(
52
+ model="Qwen/Qwen3-235B-A22B",
53
+ messages=[
54
+ {
55
+ "role": "user",
56
+ "content": world_description_prompt
57
+ }
58
+ ],
59
  )
60
+ return result.choices[0].message
61
 
62
  def get_random_persona_description():
63
  return ds.shuffle().select([100])[0]["persona"]
 
77
  yield image
78
 
79
  def generate_character(world_description, persona_description, progress=gr.Progress(track_tqdm=True)):
80
+ result = llm_client.chat.completions.create(
81
+ model="Qwen/Qwen3-235B-A22B",
82
+ messages=[
83
+ {
84
+ "role": "user",
85
+ "content": prompt_template.format(
86
+ persona_description=persona_description, world_description=world_description
87
+ )
88
+ }
89
+ ],
90
  )
91
+ output = json.loads(result.choices[0].message)
92
  return output
93
 
94
  app_description = """