Spaces:
Running
Running
Add Flux prompt generation tool
Browse files
app.py
CHANGED
@@ -33,6 +33,60 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
33 |
except Exception as e:
|
34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
final_answer = FinalAnswerTool()
|
38 |
|
@@ -55,7 +109,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
55 |
|
56 |
agent = CodeAgent(
|
57 |
model=model,
|
58 |
-
tools=[final_answer,
|
59 |
max_steps=6,
|
60 |
verbosity_level=1,
|
61 |
grammar=None,
|
|
|
33 |
except Exception as e:
|
34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
35 |
|
36 |
+
@tool
|
37 |
+
def llm_tool(user_prompt: str) -> str:
|
38 |
+
|
39 |
+
"""Executes a prompt using a language model to create a detaled prompt
|
40 |
+
for image generation based on user_prompt.
|
41 |
+
Returns prompt for image_generation_tool.
|
42 |
+
|
43 |
+
Args:
|
44 |
+
user_prompt: The user's text prompt to be processed by the language model.
|
45 |
+
"""
|
46 |
+
# Prompt parts
|
47 |
+
prefix="Generate a detailed and structured FLUX-Schnell-compatible prompt based on the following short description of an image: "
|
48 |
+
postfix="""
|
49 |
+
The generated prompt should follow these guidelines:
|
50 |
+
1. Foreground, Middle Ground, and Background: Clearly describe elements in each layer of the image in an organized manner.
|
51 |
+
2. Tone and Style: Specify the tone (e.g., cinematic, surreal, vibrant) and artistic style (e.g., photorealistic, painterly, abstract).
|
52 |
+
3. Color Palette: Include details about the dominant colors or overall color scheme.
|
53 |
+
4. Perspective and Camera Details: Mention the point of view (e.g., wide-angle, close-up), camera type, lens, aperture, and lighting conditions if applicable.
|
54 |
+
5. Additional Details: Highlight any specific objects, text, or unique features with clear emphasis (e.g., ‘with green text’ or ‘emphasis on golden hour lighting’).
|
55 |
+
6. Output Settings: Suggest aspect ratio, output format (e.g., PNG), quality level, and seed for reproducibility.
|
56 |
+
Ensure that the generated prompt is logical, descriptive, and written in natural language to maximize compatibility with FLUX-Schnell’s capabilities.”
|
57 |
+
Example Input:
|
58 |
+
'An image of a serene forest with a small cabin.'
|
59 |
+
Example Output:
|
60 |
+
'''
|
61 |
+
In the foreground, a lush green forest floor covered with moss and scattered wildflowers.
|
62 |
+
In the middle ground, a cozy wooden cabin with smoke gently rising from its chimney.
|
63 |
+
In the background, towering pine trees fading into a misty horizon.
|
64 |
+
The tone is tranquil and inviting, with a photorealistic style.
|
65 |
+
The color palette includes rich greens, warm browns for the cabin, and soft gray mist.
|
66 |
+
The perspective is slightly elevated as if viewed from a drone camera at sunrise,
|
67 |
+
capturing golden hour lighting for soft shadows and warm highlights.
|
68 |
+
The aspect ratio is 16:9 in PNG format with high quality (90), using seed 42 for reproducibility.
|
69 |
+
'''
|
70 |
+
"""
|
71 |
+
model = HfApiModel(
|
72 |
+
max_tokens=200,
|
73 |
+
temperature=1.0,
|
74 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
75 |
+
custom_role_conversions=None,
|
76 |
+
)
|
77 |
+
prompt = prefix + user_prompt + '. ' + postfix
|
78 |
+
try:
|
79 |
+
response = model.generate(
|
80 |
+
prompt=prompt, temperature=1., max_tokens=200)
|
81 |
+
|
82 |
+
response = openai.Completion.create(
|
83 |
+
engine=model_name, # Use 'engine' for older models, 'model' for newer
|
84 |
+
prompt=prompt
|
85 |
+
)
|
86 |
+
return response.choices[0].text.strip()
|
87 |
+
|
88 |
+
except Exception as e:
|
89 |
+
return f"Error during LLM call: {str(e)}"
|
90 |
|
91 |
final_answer = FinalAnswerTool()
|
92 |
|
|
|
109 |
|
110 |
agent = CodeAgent(
|
111 |
model=model,
|
112 |
+
tools=[final_answer, llm_tool, image_generation_tool], ## add your tools here (don't remove final answer)
|
113 |
max_steps=6,
|
114 |
verbosity_level=1,
|
115 |
grammar=None,
|