Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,44 +18,6 @@ from tools.final_answer import FinalAnswerTool
|
|
| 18 |
from Gradio_UI import GradioUI
|
| 19 |
|
| 20 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 21 |
-
@tool
|
| 22 |
-
def generate_image(description: str) -> str:
|
| 23 |
-
"""Generates an image based on the provided description using Hugging Face's image generation tool."""
|
| 24 |
-
try:
|
| 25 |
-
API_KEY = os.getenv("HUGGINGFACE_API_KEY")
|
| 26 |
-
if not API_KEY:
|
| 27 |
-
return "Error: HuggingFace API key is not set."
|
| 28 |
-
|
| 29 |
-
headers = {
|
| 30 |
-
"Authorization": f"Bearer {API_KEY}",
|
| 31 |
-
"Content-Type": "application/json",
|
| 32 |
-
}
|
| 33 |
-
|
| 34 |
-
payload = {
|
| 35 |
-
"model": "stability-ai/sdxl",
|
| 36 |
-
"inputs": description,
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
response = requests.post(
|
| 40 |
-
"https://api-inference.huggingface.co/pipeline/image-generation",
|
| 41 |
-
headers=headers,
|
| 42 |
-
json=payload
|
| 43 |
-
)
|
| 44 |
-
|
| 45 |
-
if response.status_code == 200:
|
| 46 |
-
image_data = response.json()
|
| 47 |
-
if isinstance(image_data, list) and len(image_data) > 0:
|
| 48 |
-
image_base64 = image_data[0].get("base64")
|
| 49 |
-
if image_base64:
|
| 50 |
-
return f"Generated image (base64): {image_base64}"
|
| 51 |
-
else:
|
| 52 |
-
return "Error: No image data found in the response."
|
| 53 |
-
else:
|
| 54 |
-
return "Error: Unexpected response format."
|
| 55 |
-
else:
|
| 56 |
-
return f"Error: API request failed with status code {response.status_code}. Details: {response.text}"
|
| 57 |
-
except Exception as e:
|
| 58 |
-
return f"Error generating image: {str(e)}"
|
| 59 |
|
| 60 |
@tool
|
| 61 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 18 |
from Gradio_UI import GradioUI
|
| 19 |
|
| 20 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
@tool
|
| 23 |
def get_current_time_in_timezone(timezone: str) -> str:
|