Spaces:
Build error
Build error
T-K-O-H commited on
Commit ·
c2837fb
1
Parent(s): d2e53aa
Update
Browse files
app.py
CHANGED
|
@@ -18,6 +18,7 @@ from langchain.schema import SystemMessage
|
|
| 18 |
import logging
|
| 19 |
import sys
|
| 20 |
from langchain_community.utilities import DuckDuckGoSearchAPIWrapper
|
|
|
|
| 21 |
|
| 22 |
# LangChain
|
| 23 |
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage, ToolMessage
|
|
@@ -74,10 +75,23 @@ def calculate(expression: str) -> str:
|
|
| 74 |
|
| 75 |
@tool
|
| 76 |
def generate_image_prompt(description: str) -> str:
|
| 77 |
-
"""Generate
|
| 78 |
-
logger.info(f"Generating image
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
|
| 83 |
# Create tools list
|
|
|
|
| 18 |
import logging
|
| 19 |
import sys
|
| 20 |
from langchain_community.utilities import DuckDuckGoSearchAPIWrapper
|
| 21 |
+
from openai import OpenAI
|
| 22 |
|
| 23 |
# LangChain
|
| 24 |
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage, ToolMessage
|
|
|
|
| 75 |
|
| 76 |
@tool
|
| 77 |
def generate_image_prompt(description: str) -> str:
|
| 78 |
+
"""Generate an image based on a description using DALL-E."""
|
| 79 |
+
logger.info(f"Generating image for: {description}")
|
| 80 |
+
try:
|
| 81 |
+
client = OpenAI()
|
| 82 |
+
response = client.images.generate(
|
| 83 |
+
model="dall-e-3",
|
| 84 |
+
prompt=description,
|
| 85 |
+
size="1024x1024",
|
| 86 |
+
quality="standard",
|
| 87 |
+
n=1,
|
| 88 |
+
)
|
| 89 |
+
image_url = response.data[0].url
|
| 90 |
+
logger.info(f"Image generated successfully: {image_url}")
|
| 91 |
+
return f"Here's the generated image: {image_url}"
|
| 92 |
+
except Exception as e:
|
| 93 |
+
logger.error(f"Error generating image: {str(e)}")
|
| 94 |
+
return f"Error generating image: {str(e)}"
|
| 95 |
|
| 96 |
|
| 97 |
# Create tools list
|