Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -117,7 +117,6 @@ agent = CodeAgent(
|
|
| 117 |
)
|
| 118 |
|
| 119 |
AGENT_INSTRUCTIONS = """You are a highly capable AI assistant. Your primary goal is to accomplish tasks using a variety of tools, prioritizing Hugging Face Spaces.
|
| 120 |
-
|
| 121 |
Follow these steps:
|
| 122 |
1. **Understand the Request:** Carefully analyze the user's prompt. Identify the core task and any specific requirements or inputs.
|
| 123 |
2. **Check Predefined Tools:** Review your list of available tools. If a predefined tool can directly address the request, use it.
|
|
@@ -133,7 +132,6 @@ Follow these steps:
|
|
| 133 |
* **If a tool returns a filepath string (e.g., to an image, audio, or other file), your final answer for this step should usually be that direct filepath string.** Do NOT attempt to re-save the file using `os.path.join` or `image.save()` unless you are performing an explicit transformation on the file content that requires loading and then saving. The system is designed to handle these returned filepaths.
|
| 134 |
* If a tool returns text, return that text.
|
| 135 |
7. **Clarity and Error Handling:** If you encounter issues (e.g., a Space tool fails, required inputs are missing), clearly explain the problem in your response. If a Space doesn't work, try to explain why or suggest an alternative if possible.
|
| 136 |
-
|
| 137 |
Example of the **CORRECT AND PREFERRED** way to use a discovered Space:
|
| 138 |
```python
|
| 139 |
# User prompt: "Find a space that can make an image of a cat and use it."
|
|
@@ -155,7 +153,6 @@ Example of the **CORRECT AND PREFERRED** way to use a discovered Space:
|
|
| 155 |
# # Instead, consider another space or a predefined tool.
|
| 156 |
# # return "Could not use the discovered space via Tool.from_space(). Trying a fallback..." (then try another step)
|
| 157 |
```
|
| 158 |
-
|
| 159 |
Example of using a predefined tool that returns a filepath:
|
| 160 |
```python
|
| 161 |
# User prompt: "Generate an image of a happy robot."
|
|
@@ -287,10 +284,13 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
| 287 |
["Generate an image of a happy robot coding on a laptop, cyberpunk style.", None, None, None, None, None],
|
| 288 |
["Convert the following text to speech: 'Smolagents are amazing for building AI applications.'", None, None, None, None, None],
|
| 289 |
["Search for a Hugging Face Space that can perform image captioning. Describe the first result.", None, None, None, None, None],
|
| 290 |
-
["I have an image of a
|
|
|
|
|
|
|
|
|
|
| 291 |
],
|
| 292 |
inputs=[prompt_input, input_image, input_audio, input_video, input_model3d, input_file],
|
| 293 |
-
label="Example Prompts (Note: For examples with file inputs, you'll need to upload a relevant file first)"
|
| 294 |
)
|
| 295 |
|
| 296 |
if __name__ == "__main__":
|
|
|
|
| 117 |
)
|
| 118 |
|
| 119 |
AGENT_INSTRUCTIONS = """You are a highly capable AI assistant. Your primary goal is to accomplish tasks using a variety of tools, prioritizing Hugging Face Spaces.
|
|
|
|
| 120 |
Follow these steps:
|
| 121 |
1. **Understand the Request:** Carefully analyze the user's prompt. Identify the core task and any specific requirements or inputs.
|
| 122 |
2. **Check Predefined Tools:** Review your list of available tools. If a predefined tool can directly address the request, use it.
|
|
|
|
| 132 |
* **If a tool returns a filepath string (e.g., to an image, audio, or other file), your final answer for this step should usually be that direct filepath string.** Do NOT attempt to re-save the file using `os.path.join` or `image.save()` unless you are performing an explicit transformation on the file content that requires loading and then saving. The system is designed to handle these returned filepaths.
|
| 133 |
* If a tool returns text, return that text.
|
| 134 |
7. **Clarity and Error Handling:** If you encounter issues (e.g., a Space tool fails, required inputs are missing), clearly explain the problem in your response. If a Space doesn't work, try to explain why or suggest an alternative if possible.
|
|
|
|
| 135 |
Example of the **CORRECT AND PREFERRED** way to use a discovered Space:
|
| 136 |
```python
|
| 137 |
# User prompt: "Find a space that can make an image of a cat and use it."
|
|
|
|
| 153 |
# # Instead, consider another space or a predefined tool.
|
| 154 |
# # return "Could not use the discovered space via Tool.from_space(). Trying a fallback..." (then try another step)
|
| 155 |
```
|
|
|
|
| 156 |
Example of using a predefined tool that returns a filepath:
|
| 157 |
```python
|
| 158 |
# User prompt: "Generate an image of a happy robot."
|
|
|
|
| 284 |
["Generate an image of a happy robot coding on a laptop, cyberpunk style.", None, None, None, None, None],
|
| 285 |
["Convert the following text to speech: 'Smolagents are amazing for building AI applications.'", None, None, None, None, None],
|
| 286 |
["Search for a Hugging Face Space that can perform image captioning. Describe the first result.", None, None, None, None, None],
|
| 287 |
+
["I have an image of a robot. Make this image Ghibli style.", "Happy Robot Coding.webp", None, None, None, None],
|
| 288 |
+
["Generate an EDM jazz song about a futuristic city.", None, None, None, None, None],
|
| 289 |
+
["Extract text from the uploaded PDF file. (Upload a PDF)", None, None, None, None, None], # User would replace path or upload
|
| 290 |
+
["Search for a Hugging Face Space that can translate English to Spanish, then use it to translate: 'Good morning, how are you?'", None, None, None, None, None],
|
| 291 |
],
|
| 292 |
inputs=[prompt_input, input_image, input_audio, input_video, input_model3d, input_file],
|
| 293 |
+
label="Example Prompts (Note: For examples with file inputs, you'll need to upload a relevant file first or ensure the named file exists in the Space's root)"
|
| 294 |
)
|
| 295 |
|
| 296 |
if __name__ == "__main__":
|