Update app.py
Browse files
app.py
CHANGED
|
@@ -54,30 +54,41 @@ def generate_keywords(topic: str, num_keywords: int) -> str:
|
|
| 54 |
]
|
| 55 |
|
| 56 |
import random
|
| 57 |
-
|
| 58 |
-
final_answer = FinalAnswerTool()
|
| 59 |
-
|
| 60 |
-
# 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:
|
| 61 |
-
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 62 |
-
|
| 63 |
-
model = HfApiModel(
|
| 64 |
-
max_tokens=2096,
|
| 65 |
-
temperature=0.5,
|
| 66 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
| 67 |
-
custom_role_conversions=None,
|
| 68 |
-
)
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
# Import tool from Hub
|
| 72 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 73 |
-
|
| 74 |
-
with open("prompts.yaml", 'r') as stream:
|
| 75 |
-
prompt_templates = yaml.safe_load(stream)
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
agent = CodeAgent(
|
| 78 |
-
model
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
max_steps=6,
|
| 82 |
verbosity_level=1,
|
| 83 |
grammar=None,
|
|
@@ -85,7 +96,7 @@ agent = CodeAgent(
|
|
| 85 |
name=None,
|
| 86 |
description=None,
|
| 87 |
prompt_templates=prompt_templates
|
| 88 |
-
|
| 89 |
|
| 90 |
|
| 91 |
GradioUI(agent).launch()
|
|
|
|
| 54 |
]
|
| 55 |
|
| 56 |
import random
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
+
# Ensure number of keywords is within reasonable range
|
| 59 |
+
num_keywords = max(1, min(20, num_keywords))
|
| 60 |
+
|
| 61 |
+
# Generate keyword combinations
|
| 62 |
+
keywords = set()
|
| 63 |
+
while len(keywords) < num_keywords:
|
| 64 |
+
keyword_type = random.randint(1, 3)
|
| 65 |
+
|
| 66 |
+
if keyword_type == 1:
|
| 67 |
+
keyword = f"{random.choice(modifiers)} {topic}"
|
| 68 |
+
elif keyword_type == 2:
|
| 69 |
+
keyword = f"{topic} {random.choice(suffixes)}"
|
| 70 |
+
else:
|
| 71 |
+
keyword = f"{random.choice(modifiers)} {topic} {random.choice(suffixes)}"
|
| 72 |
+
|
| 73 |
+
keywords.add(keyword)
|
| 74 |
+
|
| 75 |
+
# Format the response
|
| 76 |
+
response = f"""Ключевые слова по теме "{topic}":\n\n"""
|
| 77 |
+
for i, keyword in enumerate(keywords, 1):
|
| 78 |
+
response += f"{i}. {keyword}\n"
|
| 79 |
+
|
| 80 |
+
return response
|
| 81 |
+
|
| 82 |
+
# Правильное создание агента
|
| 83 |
agent = CodeAgent(
|
| 84 |
+
model,
|
| 85 |
+
[
|
| 86 |
+
image_generation_tool,
|
| 87 |
+
get_current_time_in_timezone,
|
| 88 |
+
generate_keywords,
|
| 89 |
+
final_answer,
|
| 90 |
+
DuckDuckGoSearchTool()
|
| 91 |
+
],
|
| 92 |
max_steps=6,
|
| 93 |
verbosity_level=1,
|
| 94 |
grammar=None,
|
|
|
|
| 96 |
name=None,
|
| 97 |
description=None,
|
| 98 |
prompt_templates=prompt_templates
|
| 99 |
+
)
|
| 100 |
|
| 101 |
|
| 102 |
GradioUI(agent).launch()
|