Spaces:
Sleeping
Sleeping
File size: 4,479 Bytes
9b5b26a c19d193 e97b61c 6aae614 8fe992b 556b4ea 9b5b26a e97b61c 9b5b26a 3acb222 174cd57 4234a12 174cd57 4234a12 52ee0b4 62e34a5 ef45bad b8f11e7 62e34a5 f468f26 62e34a5 5112d59 9b5b26a 2ce4add d4781ce 6aae614 ae7a494 e121372 bf6d34c 095eb03 d4cb7eb 095eb03 fe328e0 13d500a 8c01ffb 861422e 9b5b26a 8c01ffb 8fe992b 504b790 8c01ffb 861422e 8fe992b 4234a12 8fe992b 556b4ea | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
import datetime
import requests
import pytz
import yaml
import re
from tools.final_answer import FinalAnswerTool
from Gradio_UI import GradioUI
# Below is an example of a tool that does nothing. Amaze us with your creativity !
@tool
def mutante_unicorn(animal_name:str) -> str: #it's import to specify the return type
#Keep this format for the description / args / args description but feel free to modify the tool
"""A tool that generates a close-up photograph of a mutant unicorn based on the provided animal name (e.g. tiger, duck, snake, etc).
The image features a mutant unicorn with characteristics of the specified animal, butterfly wings, and tiny paws holding a bright,
colorful orb. The unicorn is gazing with concentration at the center of the orb. The scene takes place in a
forest clearing illuminated by moonlight.
Args:
animal_name: A string representing the name of an animal (e.g., "tiger", "duck", "snake") whose features will be incorporated into the mutant unicorn.
"""
try:
# Import tool from Hub
#prompt = f"A close-up, highly detailed photograph of a mutant unicorn with {animal_name}-like torso. "\
# f"It has colorful butterfly wings spreading from its back and tiny paws holding a bright, "\
# f"glowing orb. The unicorn stares with concentration at the center of the orb. "\
# f"The scene takes place in a mystical forest clearing bathed in soft moonlight. "\
# f"Professional photography, 8k, hyper-realistic."
prompt = f"A close-up, highly detailed photograph of a mutant unicorn with {animal_name}-like features. "\
f"It displays majestic characteristics typical of a {animal_name}. "\
f"It has the body structure reminiscent of a {animal_name} but with a unicorn horn. "\
f"It has beautiful, iridescent butterfly wings spreading from its back and tiny, delicate paws "\
f"holding a small glowing orb that radiates with colorful light. "\
f"The creature is staring intensely at the center of the orb with a concentrated gaze. "\
f"The scene takes place in a magical forest clearing bathed in soft, ethereal moonlight. "\
f"The background shows silhouettes of trees and some glowing fireflies. "\
f"Photorealistic style, 8K resolution, professional photography."
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
image = image_generation_tool(prompt)
return final_answer(image)
except Exception as e:
return f"Error creating a mutant unicorn for '{animal_name}': {str(e)}"
#@tool
#def describe_animal(animal_name:str) -> str:
# """Look up for the name of the animal inwikipedia using websearch tool, and then provide a 300 characters description about that animal
# Args:
# animal_name: The name of the animal to look up for in wikipedia
# """
# query = f"{animal_name} wikipedia"
# wikipedia_results = DuckDuckGoSearchTool(query)
# return wikipedia_results
final_answer = FinalAnswerTool()
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
model = HfApiModel(
max_tokens=2096,
temperature=0.5,
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
# model_id = 'meta-llama/Llama-3.3-70B-Instruct',
# model_id = 'https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',
custom_role_conversions=None,
)
with open("prompts.yaml", 'r') as stream:
prompt_templates = yaml.safe_load(stream)
agent = CodeAgent(
model=model,
tools=[final_answer, mutante_unicorn], # add your tools here (don't remove final answer)
max_steps=6,
verbosity_level=1,
grammar=None,
planning_interval=None,
name=None,
description=None,
prompt_templates=prompt_templates
)
# agent.run(
# '''This mutant unicorn has butterfly wings and is holding a small brightfull orb with its tiny paws, looking at the center
# of the orb with a concentrated gaze. The unicorn is in a clearing in the forest on a moonlit night.'''
#)
GradioUI(agent).launch() |