Spaces:
Sleeping
Sleeping
Update app.py
Browse filesadded langchain
app.py
CHANGED
@@ -5,7 +5,11 @@ import yaml
|
|
5 |
from tools.final_answer import FinalAnswerTool
|
6 |
from Gradio_UI import GradioUI
|
7 |
|
8 |
-
#
|
|
|
|
|
|
|
|
|
9 |
|
10 |
@tool
|
11 |
def my_custom_tool(arg1: str, arg2: int) -> str:
|
@@ -68,19 +72,19 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
68 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
69 |
|
70 |
|
71 |
-
# Create the image generation tool from
|
72 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
73 |
|
74 |
# ── NEW TOOL: prompte_chakwal ──
|
75 |
@tool
|
76 |
def prompte_chakwal(custom_note: str = "", num_results: int = 3) -> str:
|
77 |
"""
|
78 |
-
A tool that promotes Chakwal by retrieving real-time information and generating
|
79 |
-
It provides the current local time, live news about Chakwal from DuckDuckGo, and creates
|
80 |
-
|
81 |
|
82 |
Args:
|
83 |
-
custom_note: A custom note to add a specific theme to the generated
|
84 |
num_results: The maximum number of real-time search results (news/information) to include.
|
85 |
"""
|
86 |
output_lines = []
|
@@ -110,15 +114,23 @@ def prompte_chakwal(custom_note: str = "", num_results: int = 3) -> str:
|
|
110 |
else:
|
111 |
output_lines.append("\nNo real-time information available.")
|
112 |
|
113 |
-
# 3. Generate a promotional image using the
|
114 |
image_prompt = "A breathtaking view of Chakwal showcasing its natural beauty, vibrant culture, and historical landmarks"
|
115 |
if custom_note:
|
116 |
image_prompt += f". Theme: {custom_note}"
|
117 |
|
118 |
generated_image = image_generation_tool(image_prompt)
|
119 |
-
output_lines.append("\nGenerated Promotional Image:")
|
120 |
output_lines.append(f"{generated_image}")
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
return "\n".join(output_lines)
|
123 |
|
124 |
|
|
|
5 |
from tools.final_answer import FinalAnswerTool
|
6 |
from Gradio_UI import GradioUI
|
7 |
|
8 |
+
# Import LangChain’s Replicate tool for image generation.
|
9 |
+
from langchain.tools.replicate import ReplicateTool
|
10 |
+
|
11 |
+
# Instantiate LangChain image generation tool using a Stable Diffusion model.
|
12 |
+
langchain_image_tool = ReplicateTool(model="stability-ai/stable-diffusion")
|
13 |
|
14 |
@tool
|
15 |
def my_custom_tool(arg1: str, arg2: int) -> str:
|
|
|
72 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
73 |
|
74 |
|
75 |
+
# Create the image generation tool from smolagents.
|
76 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
77 |
|
78 |
# ── NEW TOOL: prompte_chakwal ──
|
79 |
@tool
|
80 |
def prompte_chakwal(custom_note: str = "", num_results: int = 3) -> str:
|
81 |
"""
|
82 |
+
A tool that promotes Chakwal by retrieving real-time information and generating promotional images.
|
83 |
+
It provides the current local time, live news about Chakwal from DuckDuckGo, and creates images that
|
84 |
+
highlight the city's natural beauty and vibrant culture using two different image generators.
|
85 |
|
86 |
Args:
|
87 |
+
custom_note: A custom note to add a specific theme to the generated images.
|
88 |
num_results: The maximum number of real-time search results (news/information) to include.
|
89 |
"""
|
90 |
output_lines = []
|
|
|
114 |
else:
|
115 |
output_lines.append("\nNo real-time information available.")
|
116 |
|
117 |
+
# 3. Generate a promotional image using the original image_generation_tool.
|
118 |
image_prompt = "A breathtaking view of Chakwal showcasing its natural beauty, vibrant culture, and historical landmarks"
|
119 |
if custom_note:
|
120 |
image_prompt += f". Theme: {custom_note}"
|
121 |
|
122 |
generated_image = image_generation_tool(image_prompt)
|
123 |
+
output_lines.append("\nGenerated Promotional Image (smolagents):")
|
124 |
output_lines.append(f"{generated_image}")
|
125 |
|
126 |
+
# 4. Generate a promotional image using LangChain's image generation (ReplicateTool)
|
127 |
+
try:
|
128 |
+
generated_image_langchain = langchain_image_tool.run(image_prompt)
|
129 |
+
output_lines.append("\nGenerated Promotional Image (LangChain):")
|
130 |
+
output_lines.append(f"{generated_image_langchain}")
|
131 |
+
except Exception as e:
|
132 |
+
output_lines.append(f"\nError generating image with LangChain: {e}")
|
133 |
+
|
134 |
return "\n".join(output_lines)
|
135 |
|
136 |
|