salomonsky commited on
Commit
b0241f6
1 Parent(s): 8221a06

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -20
app.py CHANGED
@@ -33,6 +33,8 @@ def enable_lora(lora_add):
33
  else:
34
  return lora_add
35
 
 
 
36
  async def generate_image(
37
  prompt:str,
38
  model:str,
@@ -50,7 +52,6 @@ async def generate_image(
50
 
51
  text = str(translator.translate(prompt, 'English')) + "," + lora_word
52
 
53
- client = AsyncInferenceClient()
54
  try:
55
  image = await client.text_to_image(
56
  prompt=text,
@@ -66,23 +67,13 @@ async def generate_image(
66
  return image, seed
67
 
68
  async def upscale_image(image, upscale_factor):
69
- client = AsyncInferenceClient()
70
  try:
71
- result = await client.predict(
72
- input_image=image,
73
  prompt="",
74
- negative_prompt="",
75
- seed=42,
76
- upscale_factor=upscale_factor,
77
- controlnet_scale=0.6,
78
- controlnet_decay=1,
79
- condition_scale=6,
80
- tile_width=112,
81
- tile_height=144,
82
- denoise_strength=0.35,
83
  num_inference_steps=18,
84
- solver="DDIM",
85
- api_name="/process",
86
  model="finegrain/finegrain-image-enhancer"
87
  )
88
  except Exception as e:
@@ -99,15 +90,12 @@ async def gen(
99
  scales:float=3.5,
100
  steps:int=24,
101
  seed:int=-1,
102
- upscale_factor:int=2,
103
- progress=gr.Progress(track_tqdm=True)
104
  ):
105
  model = enable_lora(lora_add)
106
  image, seed = await generate_image(prompt,model,lora_word,width,height,scales,steps,seed)
107
- image_path = "image.png"
108
- image.save(image_path)
109
 
110
- upscaled_image = await upscale_image(image_path, upscale_factor)
111
  return upscaled_image, seed
112
 
113
  with gr.Blocks(css=CSS, js=JS, theme="Nymbo/Nymbo_Theme") as demo:
 
33
  else:
34
  return lora_add
35
 
36
+ client = AsyncInferenceClient()
37
+
38
  async def generate_image(
39
  prompt:str,
40
  model:str,
 
52
 
53
  text = str(translator.translate(prompt, 'English')) + "," + lora_word
54
 
 
55
  try:
56
  image = await client.text_to_image(
57
  prompt=text,
 
67
  return image, seed
68
 
69
  async def upscale_image(image, upscale_factor):
 
70
  try:
71
+ result = await client.text_to_image(
 
72
  prompt="",
73
+ height=image.height * upscale_factor,
74
+ width=image.width * upscale_factor,
75
+ guidance_scale=3.5,
 
 
 
 
 
 
76
  num_inference_steps=18,
 
 
77
  model="finegrain/finegrain-image-enhancer"
78
  )
79
  except Exception as e:
 
90
  scales:float=3.5,
91
  steps:int=24,
92
  seed:int=-1,
93
+ upscale_factor:int=2
 
94
  ):
95
  model = enable_lora(lora_add)
96
  image, seed = await generate_image(prompt,model,lora_word,width,height,scales,steps,seed)
 
 
97
 
98
+ upscaled_image = await upscale_image(image, upscale_factor)
99
  return upscaled_image, seed
100
 
101
  with gr.Blocks(css=CSS, js=JS, theme="Nymbo/Nymbo_Theme") as demo: