Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from crewai import Crew, Agent, Process
|
| 3 |
+
from tools import tool
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
# Load environment variables
|
| 8 |
+
load_dotenv()
|
| 9 |
+
|
| 10 |
+
# Initialize Google Generative AI model
|
| 11 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 12 |
+
llm = ChatGoogleGenerativeAI(
|
| 13 |
+
model="gemini-1.5-flash",
|
| 14 |
+
verbose=True,
|
| 15 |
+
temperature=0.5,
|
| 16 |
+
google_api_key= "AIzaSyDy02GtpV6-VcdeCZNLJT-c4kWuPxBRbrI"
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
# Define agents
|
| 20 |
+
news_researcher = Agent(
|
| 21 |
+
role="Senior Researcher",
|
| 22 |
+
goal='Uncover groundbreaking technologies in {topic}',
|
| 23 |
+
verbose=True,
|
| 24 |
+
memory=True,
|
| 25 |
+
backstory=(
|
| 26 |
+
"Driven by curiosity, you're at the forefront of"
|
| 27 |
+
"innovation, eager to explore and share knowledge that could change"
|
| 28 |
+
"the world."
|
| 29 |
+
),
|
| 30 |
+
tools=[tool],
|
| 31 |
+
llm=llm,
|
| 32 |
+
allow_delegation=True
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
news_writer = Agent(
|
| 36 |
+
role='Writer',
|
| 37 |
+
goal='Narrate compelling tech stories about {topic}',
|
| 38 |
+
verbose=True,
|
| 39 |
+
memory=True,
|
| 40 |
+
backstory=(
|
| 41 |
+
"With a flair for simplifying complex topics, you craft"
|
| 42 |
+
"engaging narratives that captivate and educate, bringing new"
|
| 43 |
+
"discoveries to light in an accessible manner."
|
| 44 |
+
),
|
| 45 |
+
tools=[tool],
|
| 46 |
+
llm=llm,
|
| 47 |
+
allow_delegation=False
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
# Define tasks
|
| 51 |
+
research_task = Task(
|
| 52 |
+
description=(
|
| 53 |
+
"Identify the next big trend in {topic}."
|
| 54 |
+
"Focus on identifying pros and cons and the overall narrative."
|
| 55 |
+
"Your final report should clearly articulate the key points,"
|
| 56 |
+
"its market opportunities, and potential risks."
|
| 57 |
+
),
|
| 58 |
+
expected_output='A comprehensive 3 paragraphs long report on the latest AI trends.',
|
| 59 |
+
tools=[tool],
|
| 60 |
+
agent=news_researcher,
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
write_task = Task(
|
| 64 |
+
description=(
|
| 65 |
+
"Compose an insightful article on {topic}."
|
| 66 |
+
"Focus on the latest trends and how it's impacting the industry."
|
| 67 |
+
"This article should be easy to understand, engaging, and positive."
|
| 68 |
+
),
|
| 69 |
+
expected_output='A 4 paragraph article on {topic} advancements formatted as markdown.',
|
| 70 |
+
tools=[tool],
|
| 71 |
+
agent=news_writer,
|
| 72 |
+
async_execution=False,
|
| 73 |
+
output_file='new-blog-post.md' # Example of output customization
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
# Define Crew
|
| 77 |
+
crew = Crew(
|
| 78 |
+
agents=[news_researcher, news_writer],
|
| 79 |
+
tasks=[research_task, write_task],
|
| 80 |
+
process=Process.sequential,
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
# Streamlit UI
|
| 84 |
+
st.set_page_config(
|
| 85 |
+
page_title="Tech Research and Writing",
|
| 86 |
+
page_icon="🔬",
|
| 87 |
+
layout="wide",
|
| 88 |
+
menu_items={"About": "# Made by Prathamesh Khade"}
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
st.title("Tech Research and Writing")
|
| 92 |
+
|
| 93 |
+
topic = st.text_input("Enter a topic to research and write about:")
|
| 94 |
+
|
| 95 |
+
if st.button("Start Task"):
|
| 96 |
+
if topic:
|
| 97 |
+
result = crew.kickoff(inputs={'topic': topic})
|
| 98 |
+
st.write("Task Results:")
|
| 99 |
+
st.write(result)
|
| 100 |
+
else:
|
| 101 |
+
st.error("Please enter a topic.")
|
| 102 |
+
|