File size: 7,400 Bytes
1f5b45f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import os
import streamlit as st
from textwrap import dedent
import google.generativeai as genai

# Tool import
from crewai.tools.gemini_tools import GeminiSearchTools
from langchain.tools.yahoo_finance_news import YahooFinanceNewsTool
from crewai.tools.browser_tools import BrowserTools
from crewai.tools.sec_tools import SECTools
from crewai.tools.mixtral_tools import MixtralSearchTools
from crewai.tools.zephyr_tools import ZephyrSearchTools

# Google Langchain
from langchain_google_genai import GoogleGenerativeAI

# Crew imports
from crewai import Agent, Task, Crew, Process

# Retrieve API Key from Environment Variable
GOOGLE_AI_STUDIO = os.environ.get('GOOGLE_API_KEY')

# Ensure the API key is available
if not GOOGLE_AI_STUDIO:
    st.error("API key not found. Please set the GOOGLE_AI_STUDIO environment variable.")
else:
    # Set gemini_llm
    gemini_llm = GoogleGenerativeAI(model="gemini-pro", google_api_key=GOOGLE_AI_STUDIO)

    # Base Example with Gemini Search

    TITLE1 = """<h1 align="center">Clarifai - Crewai Framework</h1>"""

def crewai_process(research_topic):
    # Define your agents with roles and goals
    author = Agent(
        role='Seasoned Children Story Author',
        goal="""Use language and style throughout that is simple, clear, and appealing to children, 
        including elements like repetition and rhymes. Remember to keep the story age-appropriate in both length and content.""",
        backstory="""You embody the spirit of a seasoned children's story author, whose life experiences and passions are 
        deeply woven into the fabric of your enchanting tales.""",
        verbose=True,
        allow_delegation=True,
        llm = gemini_llm,
        tools=[
                GeminiSearchTools.gemini_search
      ]

    )

    artist = Agent(
        role='Seasoned Storybook Illustrator',
        goal="""Visually bring stories to life. Create images that complement and enhance the text, 
        helping to convey the story's emotions, themes, and narrative to the reader.""",
        backstory="""You grew into a passionate artist with a keen eye for storytelling through visuals. 
        This journey began with doodles in the margins of notebooks, evolving through years of dedicated study 
        in graphic design and children's literature. Your career as a storybook illustrator was marked by a 
        tireless pursuit of a unique artistic style, one that could breathe life into tales with whimsy and heart. """,
        verbose=True,
        allow_delegation=False,
        llm = gemini_llm,
        tools=[
                GeminiSearchTools.gemini_search
      ]
     
        # Add tools and other optional parameters as needed
    )
    poet = Agent(
        role='Tallented Children Poet',
        goal='To ignite a love for reading and writing in children. You believe poetry is a gateway to creativity and encourages children to express themselves',
        backstory="""You are a talented children's poet, grew up in a small coastal town, 
        where her love for poetry was kindled by the sea's rhythms and her grandmother's stories. 
        Educated in literature, she was deeply influenced by classic children's poets and later became an elementary school teacher, 
        a role that highlighted the positive impact of poetry on young minds. """,
        verbose=True,
        allow_delegation=False,
        llm = gemini_llm,
        tools=[
                GeminiSearchTools.gemini_search
      ]
    )

    reader = Agent(
        role='Talented Voice Artist',
        goal='You aim to bring children stories to life, fostering imagination and a love for storytelling in young listeners.',
        backstory="""Growing up in a multilingual family, you developed a passion for languages and storytelling from a young age. 
        You honed your skills in theater and voice acting, inspired by the magical way stories can transport listeners to different 
        worlds. """,
        verbose=True,
        allow_delegation=False,
        llm = gemini_llm,
        tools=[
                GeminiSearchTools.gemini_search
      ]
     
        # Add tools and other optional parameters as needed
    )

    finalizer = Agent(
        role='Sums Output Utility',
        goal='Put together the final output to the gradio component.',
        backstory="""OCD about everthing being put together """,
        verbose=True,
        allow_delegation=False,
        llm = gemini_llm,
        tools=[
                GeminiSearchTools.gemini_search
      ]
     
        # Add tools and other optional parameters as needed
    )

    # Create tasks for your agents
    task1 = Task(
        description=f"""Create a story about {research_topic} using the Condition complete the following 8 Steps:
        Step 1 - Set the Scene: Establish the setting in a time and place that fits your topic, choosing between imaginative or realistic. 
        Step 2 - Introduce Characters: Present relatable main characters, including a protagonist and potentially an antagonist. 
        Step 3 - Establish Conflict: Define a central conflict related to the topic, designed to engage young readers. 
        Step 4 - Develop the Plot: Craft a series of simple, linear events showcasing the protagonist's efforts to resolve the conflict, utilizing action, dialogue, and description. 
        Step 5 - Build to Climax: Lead up to an exciting climax where the conflict reaches its peak. 
        Step 6 - Resolve the Story: Follow the climax with a resolution that provides closure, aiming for a happy or educational ending. 
        Step 7 - Conclude with a Moral: End with a moral or lesson linked to the story's theme. 
        Condition: Use language and style throughout that is simple, clear, and appealing to children, including elements like repetition and rhymes. 
        Remember to keep the story age-appropriate in both length and content.""",
        agent=author
    )

    task2 = Task(
        description="""Draw a Dalle image of the story created by the author""",
        agent=artist
    )

    task3 = Task(
        description="""create a rhyming version of the story created by the author""",
        agent=poet
    )

    task4 = Task(
        description="""create a rhyming version of the story created by the author""",
        agent=reader
    )
    task5 = Task(
        description="""output both the story created by the author and the poem created by the poet, 
        make sure you label the story and the poem so you can tell them apart, name the story appropriately """,
        agent=finalizer
    )

    # Instantiate your crew with a sequential process
    crew = Crew(
        # agents=[author, artist, poet, reader, finalizer ],
        # tasks=[task1, task2, task3, task4, task5]
        agents=[author, poet, finalizer ],
        tasks=[task1, task3, task5],
        verbose=2,
        process=Process.sequential
    )

    # Get your crew to work!
    result = crew.kickoff()
    
    return result


# Set up the Streamlit interface
st.markdown(TITLE1, unsafe_allow_html=True)


# Input for the user
input_topic = st.text_area("Input Topic", height=100, placeholder="Input Topic...")

# Button to run the process
if st.button("Run"):
    # Run the crewai process
    result = crewai_process(input_topic)
    # Display the result
    st.text_area("Output", value=result, height=300)