Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ from PIL import Image
|
|
| 5 |
import tempfile
|
| 6 |
import shutil
|
| 7 |
from functools import partial
|
|
|
|
| 8 |
|
| 9 |
from diffusers import StableDiffusionPipeline
|
| 10 |
from huggingface_hub import InferenceClient
|
|
@@ -35,7 +36,6 @@ try:
|
|
| 35 |
print(f"Stable Diffusion Pipeline ({IMAGE_GEN_MODEL_ID}) loaded successfully on GPU.")
|
| 36 |
except Exception as e:
|
| 37 |
print("β Error loading Stable Diffusion Pipeline:")
|
| 38 |
-
import traceback
|
| 39 |
traceback.print_exc()
|
| 40 |
pipe = None # Indicate failure to load
|
| 41 |
|
|
@@ -94,7 +94,7 @@ prompt_template = ChatPromptTemplate.from_messages(
|
|
| 94 |
[
|
| 95 |
("system", """You are a powerful AI assistant that can generate images and search the web.
|
| 96 |
You have access to the following tools: {tools}
|
| 97 |
-
Available tools: {tool_names} # <---
|
| 98 |
|
| 99 |
When you need to generate an image, use the `image_generator` tool. Its input must be a very detailed, descriptive text string.
|
| 100 |
When you need factual information or context, use the `search` tool.
|
|
@@ -108,7 +108,7 @@ Always follow these steps:
|
|
| 108 |
"""),
|
| 109 |
MessagesPlaceholder(variable_name="chat_history"),
|
| 110 |
("human", "{input}"),
|
| 111 |
-
MessagesPlaceholder(variable_name="agent_scratchpad"),
|
| 112 |
]
|
| 113 |
)
|
| 114 |
|
|
@@ -129,7 +129,11 @@ def run_agent_in_gradio(message, history):
|
|
| 129 |
chat_history.append(AIMessage(content=ai_msg))
|
| 130 |
|
| 131 |
try:
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
agent_output = response["output"]
|
| 134 |
|
| 135 |
# Check if the output is an image path from our custom tool
|
|
@@ -143,7 +147,7 @@ def run_agent_in_gradio(message, history):
|
|
| 143 |
|
| 144 |
except Exception as e:
|
| 145 |
print(f"Error running agent: {e}")
|
| 146 |
-
traceback.print_exc()
|
| 147 |
return f"β Agent encountered an error: {str(e)}"
|
| 148 |
|
| 149 |
# Gradio ChatInterface setup
|
|
|
|
| 5 |
import tempfile
|
| 6 |
import shutil
|
| 7 |
from functools import partial
|
| 8 |
+
import traceback # <--- ADDED THIS LINE: Import the traceback module
|
| 9 |
|
| 10 |
from diffusers import StableDiffusionPipeline
|
| 11 |
from huggingface_hub import InferenceClient
|
|
|
|
| 36 |
print(f"Stable Diffusion Pipeline ({IMAGE_GEN_MODEL_ID}) loaded successfully on GPU.")
|
| 37 |
except Exception as e:
|
| 38 |
print("β Error loading Stable Diffusion Pipeline:")
|
|
|
|
| 39 |
traceback.print_exc()
|
| 40 |
pipe = None # Indicate failure to load
|
| 41 |
|
|
|
|
| 94 |
[
|
| 95 |
("system", """You are a powerful AI assistant that can generate images and search the web.
|
| 96 |
You have access to the following tools: {tools}
|
| 97 |
+
Available tools: {tool_names} # <--- THIS LINE IS CRUCIAL AND MUST BE PRESENT.
|
| 98 |
|
| 99 |
When you need to generate an image, use the `image_generator` tool. Its input must be a very detailed, descriptive text string.
|
| 100 |
When you need factual information or context, use the `search` tool.
|
|
|
|
| 108 |
"""),
|
| 109 |
MessagesPlaceholder(variable_name="chat_history"),
|
| 110 |
("human", "{input}"),
|
| 111 |
+
MessagesPlaceholder(variable_name="agent_scratchpad"), # This placeholder must be present
|
| 112 |
]
|
| 113 |
)
|
| 114 |
|
|
|
|
| 129 |
chat_history.append(AIMessage(content=ai_msg))
|
| 130 |
|
| 131 |
try:
|
| 132 |
+
# Pass agent_scratchpad as an empty list for each new turn
|
| 133 |
+
# This addresses the ValueError for agent_scratchpad
|
| 134 |
+
response = agent_executor.invoke(
|
| 135 |
+
{"input": message, "chat_history": chat_history, "agent_scratchpad": []}
|
| 136 |
+
)
|
| 137 |
agent_output = response["output"]
|
| 138 |
|
| 139 |
# Check if the output is an image path from our custom tool
|
|
|
|
| 147 |
|
| 148 |
except Exception as e:
|
| 149 |
print(f"Error running agent: {e}")
|
| 150 |
+
traceback.print_exc() # This line will now work correctly
|
| 151 |
return f"β Agent encountered an error: {str(e)}"
|
| 152 |
|
| 153 |
# Gradio ChatInterface setup
|