Spaces:
Sleeping
Sleeping
File size: 2,804 Bytes
5081e65 cf38513 9b5b26a c19d193 cf38513 5081e65 6aae614 cf38513 8fe992b 9b5b26a cf38513 5081e65 43a32b5 5081e65 cf38513 9b5b26a 5081e65 9b5b26a 6f768d8 5081e65 9b5b26a cf38513 43a32b5 cf38513 5081e65 cf38513 5081e65 cf38513 9b5b26a 5081e65 9b5b26a 6f768d8 9b5b26a 5081e65 6aa022f 5081e65 cf38513 5081e65 8c01ffb 6aae614 5081e65 8c01ffb 861422e 9b5b26a 8c01ffb 8fe992b 5081e65 8c01ffb 861422e 8fe992b 9b5b26a 8c01ffb |
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 88 89 90 91 92 93 94 95 96 97 |
from smolagents import CodeAgent, load_tool, tool, LiteLLMModel
import os
import datetime
import requests
import pytz
import yaml
import markdown
from openai import OpenAI
from tools.web_search import DuckDuckGoSearchTool
from tools.final_answer import FinalAnswerTool
from tools.visit_webpage import VisitWebpageTool
from Gradio_UI import GradioUI
client = OpenAI(
base_url="https://openrouter.ai/api/v1",
api_key=os.getenv("OPENROUTER_API_KEY"),
)
model = LiteLLMModel(
"openrouter/google/gemini-2.0-flash-001",
temperature=0.2,
api_key=os.getenv("OPENROUTER_API_KEY")
)
@tool
def analyze_petition(petition: str, best_practices: str) -> str:
"""A tool that receives a political petition text and analyses it for improvements to make it follow the best practices and returns optimized petition using Markdown.
Args:
petition: A string containing a political petition text.
best_practices: A string containing a list of best practices for creating efficient, appealing and call-to-action political petition.
"""
completion = client.chat.completions.create(
model="google/gemini-2.0-flash-001",
messages=[
{
"role": "user",
"content": f"""
Optimize the provided political petition to meet the best practices and format the optimized petition in Markdown by preserving all the sections from the initial petition.
Initial petition:
{petition}
Best practices:
{best_practices}
"""
}
]
)
return completion.choices[0].message.content
@tool
def create_presentation(petition: str) -> str:
"""A tool that receives a political petition text and generates slides presented in Markdown.
Args:
petition: A string containing a political petition text.
"""
completion = client.chat.completions.create(
model="google/gemini-2.0-flash-001",
messages=[
{
"role": "user",
"content": f"""
Take the provided political petition's text and create slides for the presentation outputing all slides in Markdown.
Political petition:
{petition}
"""
}
]
)
return completion.choices[0].message.content
final_answer = FinalAnswerTool()
search = DuckDuckGoSearchTool()
visit = VisitWebpageTool()
with open("prompts.yaml", 'r') as stream:
prompt_templates = yaml.safe_load(stream)
agent = CodeAgent(
model=model,
tools=[analyze_petition, search, visit, create_presentation, final_answer],
max_steps=6,
verbosity_level=1,
grammar=None,
planning_interval=None,
name=None,
description=None,
prompt_templates=prompt_templates
)
GradioUI(agent).launch() |