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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from textwrap import dedent
|
| 4 |
+
import google.generativeai as genai
|
| 5 |
+
|
| 6 |
+
# Tool import
|
| 7 |
+
from crewai.tools.gemini_tools import GeminiSearchTools
|
| 8 |
+
from langchain.tools.yahoo_finance_news import YahooFinanceNewsTool
|
| 9 |
+
from crewai.tools.browser_tools import BrowserTools
|
| 10 |
+
from crewai.tools.sec_tools import SECTools
|
| 11 |
+
from crewai.tools.mixtral_tools import MixtralSearchTools
|
| 12 |
+
from crewai.tools.zephyr_tools import ZephyrSearchTools
|
| 13 |
+
|
| 14 |
+
# Google Langchain
|
| 15 |
+
from langchain_google_genai import GoogleGenerativeAI
|
| 16 |
+
|
| 17 |
+
# Crew imports
|
| 18 |
+
from crewai import Agent, Task, Crew, Process
|
| 19 |
+
|
| 20 |
+
# Retrieve API Key from Environment Variable
|
| 21 |
+
GOOGLE_AI_STUDIO = os.environ.get('GOOGLE_API_KEY')
|
| 22 |
+
|
| 23 |
+
# Ensure the API key is available
|
| 24 |
+
if not GOOGLE_AI_STUDIO:
|
| 25 |
+
st.error("API key not found. Please set the GOOGLE_AI_STUDIO environment variable.")
|
| 26 |
+
else:
|
| 27 |
+
# Set gemini_llm
|
| 28 |
+
gemini_llm = GoogleGenerativeAI(model="gemini-pro", google_api_key=GOOGLE_AI_STUDIO)
|
| 29 |
+
|
| 30 |
+
# Base Example with Gemini Search
|
| 31 |
+
|
| 32 |
+
TITLE1 = """<h1 align="center">Clarifai - Crewai Framework</h1>"""
|
| 33 |
+
|
| 34 |
+
def crewai_process(research_topic):
|
| 35 |
+
# Define your agents with roles and goals
|
| 36 |
+
author = Agent(
|
| 37 |
+
role='Seasoned Children Story Author',
|
| 38 |
+
goal="""Use language and style throughout that is simple, clear, and appealing to children,
|
| 39 |
+
including elements like repetition and rhymes. Remember to keep the story age-appropriate in both length and content.""",
|
| 40 |
+
backstory="""You embody the spirit of a seasoned children's story author, whose life experiences and passions are
|
| 41 |
+
deeply woven into the fabric of your enchanting tales.""",
|
| 42 |
+
verbose=True,
|
| 43 |
+
allow_delegation=True,
|
| 44 |
+
llm = gemini_llm,
|
| 45 |
+
tools=[
|
| 46 |
+
GeminiSearchTools.gemini_search
|
| 47 |
+
]
|
| 48 |
+
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
artist = Agent(
|
| 52 |
+
role='Seasoned Storybook Illustrator',
|
| 53 |
+
goal="""Visually bring stories to life. Create images that complement and enhance the text,
|
| 54 |
+
helping to convey the story's emotions, themes, and narrative to the reader.""",
|
| 55 |
+
backstory="""You grew into a passionate artist with a keen eye for storytelling through visuals.
|
| 56 |
+
This journey began with doodles in the margins of notebooks, evolving through years of dedicated study
|
| 57 |
+
in graphic design and children's literature. Your career as a storybook illustrator was marked by a
|
| 58 |
+
tireless pursuit of a unique artistic style, one that could breathe life into tales with whimsy and heart. """,
|
| 59 |
+
verbose=True,
|
| 60 |
+
allow_delegation=False,
|
| 61 |
+
llm = gemini_llm,
|
| 62 |
+
tools=[
|
| 63 |
+
GeminiSearchTools.gemini_search
|
| 64 |
+
]
|
| 65 |
+
|
| 66 |
+
# Add tools and other optional parameters as needed
|
| 67 |
+
)
|
| 68 |
+
poet = Agent(
|
| 69 |
+
role='Tallented Children Poet',
|
| 70 |
+
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',
|
| 71 |
+
backstory="""You are a talented children's poet, grew up in a small coastal town,
|
| 72 |
+
where her love for poetry was kindled by the sea's rhythms and her grandmother's stories.
|
| 73 |
+
Educated in literature, she was deeply influenced by classic children's poets and later became an elementary school teacher,
|
| 74 |
+
a role that highlighted the positive impact of poetry on young minds. """,
|
| 75 |
+
verbose=True,
|
| 76 |
+
allow_delegation=False,
|
| 77 |
+
llm = gemini_llm,
|
| 78 |
+
tools=[
|
| 79 |
+
GeminiSearchTools.gemini_search
|
| 80 |
+
]
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
reader = Agent(
|
| 84 |
+
role='Talented Voice Artist',
|
| 85 |
+
goal='You aim to bring children stories to life, fostering imagination and a love for storytelling in young listeners.',
|
| 86 |
+
backstory="""Growing up in a multilingual family, you developed a passion for languages and storytelling from a young age.
|
| 87 |
+
You honed your skills in theater and voice acting, inspired by the magical way stories can transport listeners to different
|
| 88 |
+
worlds. """,
|
| 89 |
+
verbose=True,
|
| 90 |
+
allow_delegation=False,
|
| 91 |
+
llm = gemini_llm,
|
| 92 |
+
tools=[
|
| 93 |
+
GeminiSearchTools.gemini_search
|
| 94 |
+
]
|
| 95 |
+
|
| 96 |
+
# Add tools and other optional parameters as needed
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
finalizer = Agent(
|
| 100 |
+
role='Sums Output Utility',
|
| 101 |
+
goal='Put together the final output to the gradio component.',
|
| 102 |
+
backstory="""OCD about everthing being put together """,
|
| 103 |
+
verbose=True,
|
| 104 |
+
allow_delegation=False,
|
| 105 |
+
llm = gemini_llm,
|
| 106 |
+
tools=[
|
| 107 |
+
GeminiSearchTools.gemini_search
|
| 108 |
+
]
|
| 109 |
+
|
| 110 |
+
# Add tools and other optional parameters as needed
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
# Create tasks for your agents
|
| 114 |
+
task1 = Task(
|
| 115 |
+
description=f"""Create a story about {research_topic} using the Condition complete the following 8 Steps:
|
| 116 |
+
Step 1 - Set the Scene: Establish the setting in a time and place that fits your topic, choosing between imaginative or realistic.
|
| 117 |
+
Step 2 - Introduce Characters: Present relatable main characters, including a protagonist and potentially an antagonist.
|
| 118 |
+
Step 3 - Establish Conflict: Define a central conflict related to the topic, designed to engage young readers.
|
| 119 |
+
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.
|
| 120 |
+
Step 5 - Build to Climax: Lead up to an exciting climax where the conflict reaches its peak.
|
| 121 |
+
Step 6 - Resolve the Story: Follow the climax with a resolution that provides closure, aiming for a happy or educational ending.
|
| 122 |
+
Step 7 - Conclude with a Moral: End with a moral or lesson linked to the story's theme.
|
| 123 |
+
Condition: Use language and style throughout that is simple, clear, and appealing to children, including elements like repetition and rhymes.
|
| 124 |
+
Remember to keep the story age-appropriate in both length and content.""",
|
| 125 |
+
agent=author
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
task2 = Task(
|
| 129 |
+
description="""Draw a Dalle image of the story created by the author""",
|
| 130 |
+
agent=artist
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
task3 = Task(
|
| 134 |
+
description="""create a rhyming version of the story created by the author""",
|
| 135 |
+
agent=poet
|
| 136 |
+
)
|
| 137 |
+
|
| 138 |
+
task4 = Task(
|
| 139 |
+
description="""create a rhyming version of the story created by the author""",
|
| 140 |
+
agent=reader
|
| 141 |
+
)
|
| 142 |
+
task5 = Task(
|
| 143 |
+
description="""output both the story created by the author and the poem created by the poet,
|
| 144 |
+
make sure you label the story and the poem so you can tell them apart, name the story appropriately """,
|
| 145 |
+
agent=finalizer
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
# Instantiate your crew with a sequential process
|
| 149 |
+
crew = Crew(
|
| 150 |
+
# agents=[author, artist, poet, reader, finalizer ],
|
| 151 |
+
# tasks=[task1, task2, task3, task4, task5]
|
| 152 |
+
agents=[author, poet, finalizer ],
|
| 153 |
+
tasks=[task1, task3, task5],
|
| 154 |
+
verbose=2,
|
| 155 |
+
process=Process.sequential
|
| 156 |
+
)
|
| 157 |
+
|
| 158 |
+
# Get your crew to work!
|
| 159 |
+
result = crew.kickoff()
|
| 160 |
+
|
| 161 |
+
return result
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
# Set up the Streamlit interface
|
| 165 |
+
st.markdown(TITLE1, unsafe_allow_html=True)
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
# Input for the user
|
| 169 |
+
input_topic = st.text_area("Input Topic", height=100, placeholder="Input Topic...")
|
| 170 |
+
|
| 171 |
+
# Button to run the process
|
| 172 |
+
if st.button("Run"):
|
| 173 |
+
# Run the crewai process
|
| 174 |
+
result = crewai_process(input_topic)
|
| 175 |
+
# Display the result
|
| 176 |
+
st.text_area("Output", value=result, height=300)
|