Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
| 4 |
+
from langchain.llms import HuggingFacePipeline
|
| 5 |
+
from langchain.agents import AgentType, initialize_agent, load_tools
|
| 6 |
+
from langchain.memory import ConversationBufferMemory
|
| 7 |
+
from crewai import Agent, Task, Crew, Process
|
| 8 |
+
import warnings
|
| 9 |
+
|
| 10 |
+
# Suppress warnings
|
| 11 |
+
warnings.filterwarnings('ignore')
|
| 12 |
+
|
| 13 |
+
# Install necessary libraries (this step is usually done in a requirements.txt file)
|
| 14 |
+
# !pip install crewai crewai_tools transformers litellm langchain_community langchain-huggingface
|
| 15 |
+
|
| 16 |
+
# Load the gpt-neo-125M model
|
| 17 |
+
model_name = "EleutherAI/gpt-neo-125M"
|
| 18 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 19 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 20 |
+
|
| 21 |
+
# Define the pipeline
|
| 22 |
+
llm_pipeline = pipeline(
|
| 23 |
+
"text-generation",
|
| 24 |
+
model=model,
|
| 25 |
+
tokenizer=tokenizer,
|
| 26 |
+
max_new_tokens=200, # Reduced token limit for better performance
|
| 27 |
+
temperature=0.7,
|
| 28 |
+
top_p=0.95,
|
| 29 |
+
repetition_penalty=1.15,
|
| 30 |
+
device="cpu" # Ensure the model runs on CPU
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
# Create the LangChain LLM
|
| 34 |
+
llm = HuggingFacePipeline(pipeline=llm_pipeline)
|
| 35 |
+
|
| 36 |
+
# Define agents with refined prompts
|
| 37 |
+
def create_agent(role, goal, backstory):
|
| 38 |
+
return initialize_agent(
|
| 39 |
+
tools=[],
|
| 40 |
+
llm=llm,
|
| 41 |
+
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
| 42 |
+
verbose=False, # Turn off verbose for cleaner Streamlit output
|
| 43 |
+
memory=ConversationBufferMemory(memory_key="chat_history")
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
ceo_agent = create_agent("CEO", "Oversee the overall strategy and growth of the online organic product selling platform.", "The CEO sets the vision and ensures alignment across all departments.")
|
| 47 |
+
cto_agent = create_agent("CTO", "Evaluate new technologies and recommend adoption plans.", "The CTO is responsible for technology decisions and ensuring the company stays innovative.")
|
| 48 |
+
cpo_agent = create_agent("CPO", "Manage product development and ensure product quality.", "The CPO oversees product development and ensures that products meet high standards.")
|
| 49 |
+
coo_agent = create_agent("COO", "Oversee operations and ensure efficiency.", "The COO manages day-to-day operations and ensures efficiency.")
|
| 50 |
+
director_of_product_agent = create_agent("Director of Product", "Define product features and roadmap based on user feedback and market trends.", "The Director of Product ensures that the product meets user needs and aligns with the company's strategic objectives.")
|
| 51 |
+
director_of_engineering_agent = create_agent("Director of Engineering", "Plan sprints and manage engineering teams to deliver high-quality software components.", "The Director of Engineering oversees the development process and ensures timely delivery of software features.")
|
| 52 |
+
product_manager_agent = create_agent("Product Manager", "Define product features and roadmap based on user feedback and market trends.", "The Product Manager ensures that the product meets user needs and aligns with the company's strategic objectives.")
|
| 53 |
+
engineering_manager_agent = create_agent("Engineering Manager", "Plan sprints and manage engineering teams to deliver high-quality software components.", "The Engineering Manager oversees the development process and ensures timely delivery of software features.")
|
| 54 |
+
engineer_agent = create_agent("Software Engineer", "Develop and test software components for the online organic product selling platform.", "The Software Engineer is responsible for writing clean, efficient, and maintainable code.")
|
| 55 |
+
qa_engineer_agent = create_agent("QA Engineer", "Ensure quality standards are met through thorough testing and bug fixing.", "The QA Engineer performs testing to ensure the software meets quality criteria.")
|
| 56 |
+
|
| 57 |
+
# Define tasks with refined prompts
|
| 58 |
+
def create_task(description, expected_output, agent):
|
| 59 |
+
return Task(
|
| 60 |
+
description=description,
|
| 61 |
+
expected_output=expected_output,
|
| 62 |
+
agent=agent,
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
ceo_task = create_task(
|
| 66 |
+
"Review the Q4 2024 performance report provided below and provide strategic recommendations for the next quarter. Include actionable insights, key performance indicators, and specific initiatives to drive growth and improve efficiency.",
|
| 67 |
+
"A detailed report with actionable insights for the next quarter, including key performance indicators and specific initiatives.",
|
| 68 |
+
ceo_agent,
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
# Repeat for other tasks...
|
| 72 |
+
|
| 73 |
+
# Define the crew
|
| 74 |
+
ecommerce_crew = Crew(
|
| 75 |
+
agents=[
|
| 76 |
+
ceo_agent,
|
| 77 |
+
cto_agent,
|
| 78 |
+
cpo_agent,
|
| 79 |
+
coo_agent,
|
| 80 |
+
director_of_product_agent,
|
| 81 |
+
director_of_engineering_agent,
|
| 82 |
+
product_manager_agent,
|
| 83 |
+
engineering_manager_agent,
|
| 84 |
+
engineer_agent,
|
| 85 |
+
qa_engineer_agent,
|
| 86 |
+
],
|
| 87 |
+
tasks=[
|
| 88 |
+
ceo_task,
|
| 89 |
+
# Add other tasks...
|
| 90 |
+
],
|
| 91 |
+
manager_llm=llm,
|
| 92 |
+
process=Process.hierarchical,
|
| 93 |
+
verbose=False
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
# Streamlit UI
|
| 97 |
+
st.title("E-commerce Platform Management")
|
| 98 |
+
|
| 99 |
+
# Input fields for the user
|
| 100 |
+
quarterly_report = st.text_area("Quarterly Report", value="Q4 2024 revenue increased by 15%, driven by strong demand in organic products.")
|
| 101 |
+
market_trends = st.text_area("Market Trends", value="There is a growing trend towards organic and sustainable products.")
|
| 102 |
+
user_feedback = st.text_area("User Feedback", value="Users are requesting more personalized product recommendations and better payment options.")
|
| 103 |
+
|
| 104 |
+
if st.button("Run Analysis"):
|
| 105 |
+
ecommerce_inputs = {
|
| 106 |
+
'quarterly_report': quarterly_report,
|
| 107 |
+
'market_trends': market_trends,
|
| 108 |
+
'user_feedback': user_feedback
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
result = ecommerce_crew.kickoff(inputs=ecommerce_inputs)
|
| 112 |
+
st.write(result)
|