Spaces:
Sleeping
Sleeping
Update app.py
Browse filesadded replicate and langchain
app.py
CHANGED
@@ -5,11 +5,11 @@ import yaml
|
|
5 |
from tools.final_answer import FinalAnswerTool
|
6 |
from Gradio_UI import GradioUI
|
7 |
|
8 |
-
# Import
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
|
14 |
@tool
|
15 |
def my_custom_tool(arg1: str, arg2: int) -> str:
|
@@ -114,7 +114,7 @@ def prompte_chakwal(custom_note: str = "", num_results: int = 3) -> str:
|
|
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}"
|
@@ -123,13 +123,18 @@ def prompte_chakwal(custom_note: str = "", num_results: int = 3) -> str:
|
|
123 |
output_lines.append("\nGenerated Promotional Image (smolagents):")
|
124 |
output_lines.append(f"{generated_image}")
|
125 |
|
126 |
-
# 4. Generate a promotional image using
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
return "\n".join(output_lines)
|
135 |
|
|
|
5 |
from tools.final_answer import FinalAnswerTool
|
6 |
from Gradio_UI import GradioUI
|
7 |
|
8 |
+
# Import replicate directly to generate images using Stable Diffusion.
|
9 |
+
try:
|
10 |
+
import replicate
|
11 |
+
except ModuleNotFoundError:
|
12 |
+
replicate = None
|
13 |
|
14 |
@tool
|
15 |
def my_custom_tool(arg1: str, arg2: int) -> str:
|
|
|
114 |
else:
|
115 |
output_lines.append("\nNo real-time information available.")
|
116 |
|
117 |
+
# 3. Generate a promotional image using the original smolagents 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}"
|
|
|
123 |
output_lines.append("\nGenerated Promotional Image (smolagents):")
|
124 |
output_lines.append(f"{generated_image}")
|
125 |
|
126 |
+
# 4. Generate a promotional image using the Replicate API (Stable Diffusion) if available.
|
127 |
+
if replicate:
|
128 |
+
try:
|
129 |
+
stable_diffusion = replicate.models.get("stability-ai/stable-diffusion")
|
130 |
+
# The predict method typically returns a list of image URLs.
|
131 |
+
generated_image_replicate = stable_diffusion.predict(prompt=image_prompt)
|
132 |
+
output_lines.append("\nGenerated Promotional Image (Replicate):")
|
133 |
+
output_lines.append(f"{generated_image_replicate}")
|
134 |
+
except Exception as e:
|
135 |
+
output_lines.append(f"\nError generating image with Replicate: {e}")
|
136 |
+
else:
|
137 |
+
output_lines.append("\nReplicate module is not available. Install it via 'pip install replicate'.")
|
138 |
|
139 |
return "\n".join(output_lines)
|
140 |
|