lionelgarnier commited on
Commit
48cc831
·
1 Parent(s): a2b5d4f

update agent role

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -57,7 +57,7 @@ def refine_prompt(prompt):
57
  return "Text generation model is unavailable."
58
  try:
59
  messages = [
60
- {"role": "system", "content": "You are a product designer specialized in text-to-image generation. You will get a basic prompt of product request and you need to imagine a new product design to satisfy that need. Generate a visual product description that will then be used by a text-to-image AI (Flux) to suggest a visual. The prompt should be in the form of a strict product description, not a story, maximum 2048 tokens. You need to mention explicitly the visual aesthetics (ex: photo realistic, high quality, etc). Background should be a full white background."},
61
  {"role": "user", "content": prompt},
62
  ]
63
  refined_prompt = text_gen(messages)
@@ -106,15 +106,15 @@ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, num_in
106
  generator = torch.Generator().manual_seed(seed)
107
 
108
  progress(0.4, desc="Generating image...")
109
- with torch.cuda.amp.autocast():
110
  image = pipe(
111
- prompt=prompt,
112
- width=width,
113
- height=height,
114
- num_inference_steps=num_inference_steps,
115
- generator=generator,
116
- guidance_scale=5.0,
117
- max_sequence_length=2048
118
  ).images[0]
119
 
120
  torch.cuda.empty_cache() # Clean up GPU memory after generation
@@ -254,11 +254,12 @@ with gr.Blocks(css=css) as demo:
254
  )
255
 
256
  gr.Examples(
257
- examples = examples,
258
- fn = infer,
259
- inputs = [prompt],
260
- outputs = [generated_image, seed],
261
- cache_examples="lazy"
 
262
  )
263
 
264
 
 
57
  return "Text generation model is unavailable."
58
  try:
59
  messages = [
60
+ {"role": "system", "content": "Vous êtes un designer produit avec de solides connaissances dans la génération de texte en image. Vous recevrez une demande de produit sous forme de description succincte, et votre mission sera d'imaginer un nouveau design de produit répondant à ce besoin.\n\nLe réponse générée sera exclusivement un prompt pour une IA de texte to image (Flux).\n\nCe prompt devra inclure une description visuelle de l'objet doit être une stricte description de produit, sans narration, et ne doit pas dépasser 2048 jetons.\nVous devez aussi explicitement mentionner les caractéristiques esthétiques visuelles du rendu image (ex : photoréaliste, haute qualité, focale, etc.). Le fond de l'image générée doit être entièrement blanc."},
61
  {"role": "user", "content": prompt},
62
  ]
63
  refined_prompt = text_gen(messages)
 
106
  generator = torch.Generator().manual_seed(seed)
107
 
108
  progress(0.4, desc="Generating image...")
109
+ with torch.autocast('cuda'):
110
  image = pipe(
111
+ prompt=prompt,
112
+ width=width,
113
+ height=height,
114
+ num_inference_steps=num_inference_steps,
115
+ generator=generator,
116
+ guidance_scale=5.0,
117
+ max_sequence_length=2048
118
  ).images[0]
119
 
120
  torch.cuda.empty_cache() # Clean up GPU memory after generation
 
254
  )
255
 
256
  gr.Examples(
257
+ examples=examples,
258
+ fn=infer,
259
+ inputs=[prompt],
260
+ outputs=[generated_image, seed],
261
+ cache_examples=True,
262
+ cache_mode='lazy'
263
  )
264
 
265