Spaces:
Runtime error
Runtime error
lionelgarnier
commited on
Commit
·
69e268f
1
Parent(s):
c9afdec
improve text generation
Browse files
app.py
CHANGED
@@ -44,7 +44,6 @@ def get_text_gen_pipeline():
|
|
44 |
model="mistralai/Mistral-7B-Instruct-v0.3",
|
45 |
max_new_tokens=2048,
|
46 |
device=device,
|
47 |
-
#model_kwargs={"add_prefix_space": False}
|
48 |
)
|
49 |
except Exception as e:
|
50 |
print(f"Error loading text generation model: {e}")
|
@@ -58,11 +57,16 @@ def refine_prompt(prompt):
|
|
58 |
return "Text generation model is unavailable."
|
59 |
try:
|
60 |
messages = [
|
61 |
-
{"role": "system", "content": "You are a product designer. You will get a basic prompt of product request and you need to imagine a new product design to satisfy that need.
|
62 |
{"role": "user", "content": prompt},
|
63 |
]
|
64 |
refined_prompt = text_gen(messages)
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
66 |
except Exception as e:
|
67 |
return f"Error refining prompt: {str(e)}"
|
68 |
|
|
|
44 |
model="mistralai/Mistral-7B-Instruct-v0.3",
|
45 |
max_new_tokens=2048,
|
46 |
device=device,
|
|
|
47 |
)
|
48 |
except Exception as e:
|
49 |
print(f"Error loading text generation model: {e}")
|
|
|
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."}, {"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. Genrerate a product description of product front view that will be used by a text-to-image AI (Flux) to generate a visual. The prompt should be in the form of a 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)
|
64 |
+
# Extract just the assistant's content from the response
|
65 |
+
try:
|
66 |
+
assistant_content = refined_prompt[0]['generated_text'][-1]['content']
|
67 |
+
return assistant_content
|
68 |
+
except (KeyError, IndexError):
|
69 |
+
return "Error: Unexpected response format from the model"
|
70 |
except Exception as e:
|
71 |
return f"Error refining prompt: {str(e)}"
|
72 |
|