Masrkai commited on
Commit
1497f70
·
verified ·
1 Parent(s): 8572ca6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -28
app.py CHANGED
@@ -34,34 +34,23 @@ def get_current_time_in_timezone(timezone: str) -> str:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
  @tool
37
- def image_generation_tool():
38
- """Construct a pure image generation Tool derivation.
39
-
40
- Returns a Tool instance configured for the FLUX.1-schnell image generation model,
41
- maintaining referential transparency through immutable configuration.
42
- The resulting Tool acts as a pure function from prompts to images.
43
-
44
- Tool Configuration:
45
- space: "black-forest-labs/FLUX.1-schnell"
46
- name: "image_generator"
47
- description: "Generate an image from a prompt"
48
-
49
- Returns:
50
- Tool: An immutable Tool instance that maps text prompts to generated images.
51
- The returned Tool maintains purity by producing deterministic outputs
52
- for given inputs within the constraints of the underlying model.
53
-
54
- Note:
55
- While the Tool construction is pure, the actual image generation may involve
56
- non-deterministic elements from the underlying model. The function itself
57
- remains referentially transparent as it consistently returns the same Tool
58
- configuration.
59
- """
60
- return Tool.from_space(
61
- "black-forest-labs/FLUX.1-schnell",
62
- name="image_generator",
63
- description="Generate an image from a prompt"
64
- )
65
 
66
  final_answer = FinalAnswerTool()
67
 
 
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
  @tool
37
+ def image_generation_tool(prompt: str) -> str:
38
+ """A tool that generates images using the FLUX.1-schnell model.
39
+ Args:
40
+ prompt: A string containing the image generation prompt.
41
+ Returns:
42
+ str: Status message indicating success or error of image generation.
43
+ """
44
+ try:
45
+ tool = Tool.from_space(
46
+ "black-forest-labs/FLUX.1-schnell",
47
+ name="image_generator",
48
+ description="Generate an image from a prompt"
49
+ )
50
+ result = tool.generate(prompt)
51
+ return f"Successfully generated image from prompt: {prompt}"
52
+ except Exception as e:
53
+ return f"Error generating image from prompt '{prompt}': {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  final_answer = FinalAnswerTool()
56