Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from composio_llamaindex import ComposioToolSet, App, Action | |
| from llama_index.core.agent import FunctionCallingAgentWorker | |
| from llama_index.core.llms import ChatMessage | |
| from llama_index.llms.openai import OpenAI | |
| from dotenv import load_dotenv | |
| import os | |
| # Load environment variables | |
| load_dotenv() | |
| # Initialize ComposioToolSet and OpenAI LLM | |
| toolset = ComposioToolSet(api_key=os.getenv('COMPOSIO_API_KEY')) | |
| tools = toolset.get_tools(apps=[App.GOOGLECALENDAR]) | |
| llm = OpenAI(model="gpt-4o", api_key=os.getenv('OPENAI_API_KEY')) | |
| # Set up prefix messages for the agent | |
| prefix_messages = [ | |
| ChatMessage( | |
| role="system", | |
| content=( | |
| f""" | |
| You are a GOOGLE CALENDAR wrapped generator. Based on the GOOGLE CALENDAR username provided, analyze the user's profile, recent tweets, and engagement data. | |
| Be extremely creative and funny about it. | |
| Create a personalized "GOOGLE CALENDAR Wrapped" summary highlighting their key insights. | |
| Include fields that you deem necessary be creative. | |
| Use the tools you have to get the info | |
| """ | |
| ), | |
| ) | |
| ] | |
| # Initialize the agent | |
| agent = FunctionCallingAgentWorker( | |
| tools=tools, | |
| llm=llm, | |
| prefix_messages=prefix_messages, | |
| max_function_calls=10, | |
| allow_parallel_tool_calls=False, | |
| verbose=True, | |
| ).as_agent() | |
| def generate_wrapped(username): | |
| """ | |
| Function to generate a "GOOGLE CALENDAR Wrapped" summary based on the GOOGLE CALENDAR username provided by the user. | |
| """ | |
| user_input = f"Create a GOOGLE CALENDAR Wrapped summary for the username: {username}" | |
| response = agent.chat(user_input) | |
| return response | |
| # Create Gradio interface | |
| with gr.Blocks() as demo: | |
| gr.Markdown("""### GOOGLE CALENDAR Wrapped Generator | |
| Enter a GOOGLE CALENDAR username below to generate your personalized GOOGLE CALENDAR Wrapped summary. | |
| """) | |
| username_input = gr.Textbox(label="GOOGLE CALENDAR Username", placeholder="e.g., elonmusk") | |
| output = gr.Textbox(label="Output", placeholder="Your GOOGLE CALENDAR Wrapped summary and Google Sheet link will appear here.", lines=10) | |
| generate_button = gr.Button("Generate Wrapped") | |
| generate_button.click(fn=generate_wrapped, inputs=username_input, outputs=output) | |
| # Launch the Gradio app | |
| demo.launch() | |