-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
104 lines (75 loc) · 3.18 KB
/
app.py
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
import streamlit as st
import os
from crewai import Crew
from crewai_tools import ScrapeWebsiteTool, SerperDevTool
from agents import TechAgents
from tasks import TechTasks
from langchain_openai import ChatOpenAI
st.set_page_config(page_title="SpecReview", page_icon="🔥", layout="centered", initial_sidebar_state="expanded")
# Sidebar
st.sidebar.header("Configuration")
st.session_state.openai_key = st.sidebar.text_input("API Key", type="password")
st.session_state.serper_key = st.sidebar.text_input("Serper Key", type="password")
st.session_state.llm_model_name = st.sidebar.selectbox(
"Select Model",
options=["gpt-3.5-turbo", "gpt-4", "gpt-4o"],
index=0 # Default is the first option which is "gpt-3.5-turbo"
)
if st.sidebar.button("Configure") and st.session_state.openai_key and st.session_state.serper_key:
os.environ["SERPER_API_KEY"] = st.session_state.serper_key
st.session_state.llm = ChatOpenAI(
model=st.session_state.llm_model_name,
api_key=st.session_state.openai_key
)
st.toast(f"Configuration is successful, running on {st.session_state.llm_model_name}", icon='😍')
# Main Section
st.title("SpecReview")
st.subheader("In-depth Laptop Comparison")
st.write("It is recommended to use gpt-4o model to perform this task")
col1, col2 = st.columns(2)
with col1:
st.session_state.item1 = st.text_area("Laptop 1", height=150)
with col2:
st.session_state.item2 = st.text_area("Laptop 2", height=150)
if st.button("Compare"):
search_tool = SerperDevTool()
scrape_tool = ScrapeWebsiteTool()
tools = [search_tool, scrape_tool]
if (not st.session_state.openai_key) or (not st.session_state.serper_key):
st.write("Check api keys")
else:
agents = TechAgents(st.session_state.llm, tools)
tasks = TechTasks(tools)
researcher = agents.researcher()
writer = agents.writer()
product1_research = tasks.gather_information(agent = researcher)
product2_research = tasks.gather_information(agent = researcher)
document1 = tasks.format_text(agent = writer)
document1.context = [product1_research]
document2 = tasks.format_text(agent = writer)
document2.context = [product2_research]
crew1 = Crew(
agents = [researcher],
tasks = [product1_research, document1],
verbose = True
)
crew2 = Crew(
agents = [researcher],
tasks = [product2_research, document2],
verbose = True
)
if (not st.session_state.item1) or (not st.session_state.item2):
st.write("Text fields cannot be empty")
else:
print(st.session_state.item1)
result1 = crew1.kickoff(inputs = {"item" : st.session_state.item1})
result2 = crew2.kickoff(inputs = {"item" : st.session_state.item2})
with open("result1.txt", 'w') as file:
file.write(result1)
with open("result2.txt", 'w') as file:
file.write(result2)
with col1:
st.write(result1)
with col2:
st.write(result2)
print("END OF QUERY")