Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from pandasai import SmartDataframe
|
4 |
+
from langchain_groq import ChatGroq
|
5 |
+
|
6 |
+
llm = ChatGroq(
|
7 |
+
model="llama3-70b-8192",
|
8 |
+
temperature=0.1,
|
9 |
+
max_retries=2,
|
10 |
+
)
|
11 |
+
|
12 |
+
# Initialize session state for URL and DataFrame
|
13 |
+
if 'pre_url' not in st.session_state:
|
14 |
+
st.session_state['pre_url'] = ''
|
15 |
+
if 'df' not in st.session_state:
|
16 |
+
st.session_state['df'] = None
|
17 |
+
|
18 |
+
# Streamlit app
|
19 |
+
st.title("Conversation Analysis")
|
20 |
+
|
21 |
+
# Step 1: Choose conversation
|
22 |
+
opendata_options = [
|
23 |
+
'15-per-hour-seattle', 'american-assembly.bowling-green', 'brexit-consensus',
|
24 |
+
'canadian-electoral-reform', 'football-concussions', 'march-on.operation-marchin-orders',
|
25 |
+
'scoop-hivemind.affordable-housing', 'scoop-hivemind.biodiversity',
|
26 |
+
'scoop-hivemind.freshwater', 'scoop-hivemind.taxes', 'scoop-hivemind.ubi',
|
27 |
+
'ssis.land-bank-farmland.2rumnecbeh.2021-08-01', 'vtaiwan.uberx'
|
28 |
+
]
|
29 |
+
selected_option = st.selectbox("Choose conversation", opendata_options)
|
30 |
+
|
31 |
+
url = (
|
32 |
+
f"https://raw.githubusercontent.com/compdemocracy/openData/master/{selected_option}/comments.csv"
|
33 |
+
)
|
34 |
+
|
35 |
+
# Load data only if URL changes
|
36 |
+
if st.session_state['pre_url'] != url:
|
37 |
+
df = SmartDataframe(pd.read_csv(url, index_col=0), config={"llm": llm})
|
38 |
+
st.session_state['df'] = df
|
39 |
+
st.session_state['pre_url'] = url
|
40 |
+
|
41 |
+
# Step 2: Request for analysis or chart
|
42 |
+
request = st.text_input(
|
43 |
+
"Enter your analysis request:",
|
44 |
+
"Plot a histogram about the distribution of agree, disagree and neutral comments against the topic")
|
45 |
+
|
46 |
+
# Execute chat and display results
|
47 |
+
if st.button("Analyze"):
|
48 |
+
if st.session_state['df'] is not None:
|
49 |
+
st.session_state['df'].chat(request)
|
50 |
+
else:
|
51 |
+
st.warning("Please select a conversation and load data first.")
|