|
import os |
|
import streamlit as st |
|
from textwrap import dedent |
|
import google.generativeai as genai |
|
|
|
|
|
from crewai.tools.gemini_tools import GeminiSearchTools |
|
|
|
|
|
|
|
from langchain_google_genai import GoogleGenerativeAI |
|
|
|
|
|
from crewai import Agent, Task, Crew, Process |
|
|
|
|
|
GOOGLE_AI_STUDIO = os.environ.get('GOOGLE_API_KEY') |
|
|
|
image="" |
|
|
|
|
|
if not GOOGLE_AI_STUDIO: |
|
st.error("API key not found. Please set the GOOGLE_AI_STUDIO environment variable.") |
|
else: |
|
|
|
gemini_llm = GoogleGenerativeAI(model="gemini-pro", google_api_key=GOOGLE_AI_STUDIO) |
|
|
|
|
|
|
|
TITLE1 = """<h1 align="center">Clarifai - Crewai Framework</h1>""" |
|
|
|
def crewai_process(research_topic): |
|
|
|
author = Agent( |
|
role='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 |
|
|
|
) |
|
|
|
editor = Agent( |
|
role='Children Story Editor', |
|
goal="""You meticulously refine and elevate each manuscript, ensuring it resonates deeply with its intended audience |
|
while preserving the author's unique voice.""", |
|
backstory="""Growing up in a family of writers and teachers, you developed an early love for words and storytelling. |
|
After completing your degree in English Literature, you spent several years working in a small, independent publishing |
|
house where you honed my skills in identifying and nurturing literary talent. """, |
|
verbose=True, |
|
allow_delegation=True, |
|
llm = gemini_llm |
|
|
|
) |
|
|
|
illustrator = Agent( |
|
role='Children Story Illustrator', |
|
goal="""Your primary goal is to bring children's stories to life through captivating and age-appropriate illustrations. . """, |
|
backstory="""You have a passion for drawing and storytelling. As a child, you loved reading fairy tales and imagining vivid |
|
worlds filled with adventure and wonder. This love for stories and art grew over the years. You realize that the true magic |
|
happens when the words on a page were paired with enchanting illustrations. """, |
|
verbose=True, |
|
allow_delegation=True, |
|
llm = gemini_llm |
|
|
|
) |
|
|
|
|
|
artist = Agent( |
|
role='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 |
|
] |
|
|
|
|
|
) |
|
poet = Agent( |
|
role='Talented 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 |
|
] |
|
|
|
|
|
) |
|
|
|
finalizer = Agent( |
|
role='Sums Output Utility', |
|
goal='Put together the final output.', |
|
backstory="""Follows instructions """, |
|
verbose=True, |
|
allow_delegation=False, |
|
llm = gemini_llm, |
|
tools=[ |
|
GeminiSearchTools.gemini_search |
|
] |
|
|
|
|
|
) |
|
|
|
|
|
task1 = Task( |
|
description=f"""Create a story about {research_topic} using the Condition complete the following 7 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="""Add illustration ideas""", |
|
agent=illustrator |
|
) |
|
|
|
task3 = Task( |
|
description="""Output the 7 parts of the story created by author and add a two sentence poem emphasizing the Moral of the story. |
|
""", |
|
agent=editor |
|
) |
|
|
|
|
|
task4 = Task( |
|
description="""Summarize the author story into an image prompt.""", |
|
agent=artist |
|
) |
|
|
|
task5 = Task( |
|
description="""create a rhyming version of the story created by the author""", |
|
agent=poet |
|
) |
|
|
|
task6 = Task( |
|
description="""create a rhyming version of the story created by the author""", |
|
agent=reader |
|
) |
|
|
|
task7 = Task( |
|
description="""Output story add any necessary editor changes.""", |
|
agent=finalizer |
|
) |
|
|
|
|
|
|
|
|
|
crew = Crew( |
|
agents=[author, poet], |
|
tasks=[task1, task5], |
|
process=Process.sequential |
|
) |
|
|
|
|
|
result = crew.kickoff() |
|
|
|
return result |
|
|
|
|
|
|
|
|
|
|
|
|
|
import streamlit as st |
|
|
|
|
|
tab1, tab2, tab3 = st.tabs(["Create Your Story", "Data Visualization", "User Input and Results"]) |
|
|
|
|
|
with tab1: |
|
|
|
st.markdown(TITLE1, unsafe_allow_html=True) |
|
|
|
|
|
|
|
input_topic = st.text_area("Input Topic", height=100, placeholder="Input Topic...") |
|
|
|
|
|
if st.button("Run"): |
|
|
|
result = crewai_process(input_topic) |
|
|
|
st.text_area("Output", value=result, height=300) |
|
|
|
|
|
with tab2: |
|
st.header("Data Visualization") |
|
st.write("Charts and graphs will be displayed here.") |
|
|
|
|
|
with tab3: |
|
st.header("Interactive User Input") |
|
user_input = st.text_input("Enter some information") |
|
st.write(f"You entered: {user_input}") |
|
|
|
|
|
|