salomonsky commited on
Commit
438c833
verified
1 Parent(s): cfc9459

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -77,7 +77,7 @@ async def gen(prompt, basemodel, width, height, scales, steps, seed, upscale_fac
77
  upscale_image = Image.open(upscale_image_path)
78
  upscale_image.save(DATA_PATH / f"upscale_image_{seed}.jpg", format="JPEG")
79
  progress_bar.progress(100)
80
- image_path.unlink() # Borrar la imagen original si se escal贸
81
  return [str(DATA_PATH / f"upscale_image_{seed}.jpg"), str(prompt_file_path)]
82
  else:
83
  progress_bar.empty()
@@ -88,11 +88,11 @@ async def gen(prompt, basemodel, width, height, scales, steps, seed, upscale_fac
88
 
89
  async def improve_prompt(prompt):
90
  try:
91
- instruction = ("With this idea, describe in English a detailed txt2img prompt in 200 character at most...")
92
- formatted_prompt = f"{prompt}: {instruction}"
93
- response = llm_client.text_generation(formatted_prompt, max_new_tokens=200)
94
  improved_text = response['generated_text'].strip() if 'generated_text' in response else response.strip()
95
- return improved_text[:200] if len(improved_text) > 200 else improved_text
96
  except Exception as e:
97
  return f"Error mejorando el prompt: {e}"
98
 
@@ -152,12 +152,12 @@ else:
152
  width = 1280
153
  height = 720
154
 
155
- if st.sidebar.button("Mejorar prompt"):
156
- improved_prompt = asyncio.run(improve_prompt(prompt))
157
- st.session_state.improved_prompt = improved_prompt
158
- st.write(f"Prompt mejorado: {improved_prompt}")
159
-
160
  if st.sidebar.button("Generar Imagen"):
 
 
 
 
 
161
  with st.spinner("Generando imagen..."):
162
  result = run_gen()
163
  image_paths = result[0]
 
77
  upscale_image = Image.open(upscale_image_path)
78
  upscale_image.save(DATA_PATH / f"upscale_image_{seed}.jpg", format="JPEG")
79
  progress_bar.progress(100)
80
+ image_path.unlink()
81
  return [str(DATA_PATH / f"upscale_image_{seed}.jpg"), str(prompt_file_path)]
82
  else:
83
  progress_bar.empty()
 
88
 
89
  async def improve_prompt(prompt):
90
  try:
91
+ instruction = ("With this idea, describe in English a detailed txt2img prompt in 300 character at most...")
92
+ formatted_prompt = f"{instruction}"
93
+ response = llm_client.text_generation(formatted_prompt, max_new_tokens=300)
94
  improved_text = response['generated_text'].strip() if 'generated_text' in response else response.strip()
95
+ return improved_text[:300] if len(improved_text) > 300 else improved_text
96
  except Exception as e:
97
  return f"Error mejorando el prompt: {e}"
98
 
 
152
  width = 1280
153
  height = 720
154
 
 
 
 
 
 
155
  if st.sidebar.button("Generar Imagen"):
156
+ with st.spinner("Mejorando prompt..."):
157
+ improved_prompt = asyncio.run(improve_prompt(prompt))
158
+ st.session_state.improved_prompt = improved_prompt
159
+ st.write(f"Prompt mejorado: {improved_prompt}")
160
+
161
  with st.spinner("Generando imagen..."):
162
  result = run_gen()
163
  image_paths = result[0]