|
import os |
|
import streamlit as st |
|
import pandas as pd |
|
from pandasai import Agent |
|
from langchain_groq import ChatGroq |
|
|
|
llm = ChatGroq( |
|
model="llama3-70b-8192", |
|
temperature=0, |
|
max_retries=2, |
|
) |
|
|
|
|
|
if 'pre_url' not in st.session_state: |
|
st.session_state['pre_url'] = '' |
|
if 'df' not in st.session_state: |
|
st.session_state['df'] = None |
|
|
|
|
|
st.title("Conversation Analysis") |
|
|
|
|
|
st.markdown(""" |
|
## Go beyond static visualizations! |
|
This app lets you directly ask for the insights you need from Polis conversation data. |
|
Instead of being limited to a standard PCA chart, you can request custom plots and analyses using natural language. |
|
> :bulb: For example, try asking for: "**Show me a pie chart of the most common sentiment expressed in these comments.**" |
|
""") |
|
|
|
|
|
opendata_options = [ |
|
'15-per-hour-seattle', 'american-assembly.bowling-green', 'brexit-consensus', |
|
'canadian-electoral-reform', 'football-concussions', 'march-on.operation-marchin-orders', |
|
'scoop-hivemind.affordable-housing', 'scoop-hivemind.biodiversity', |
|
'scoop-hivemind.freshwater', 'scoop-hivemind.taxes', 'scoop-hivemind.ubi', |
|
'ssis.land-bank-farmland.2rumnecbeh.2021-08-01', 'vtaiwan.uberx' |
|
] |
|
selected_option = st.selectbox("Choose conversation", opendata_options) |
|
|
|
url = ( |
|
f"https://raw.githubusercontent.com/compdemocracy/openData/master/{selected_option}/comments.csv" |
|
) |
|
|
|
|
|
if st.session_state['pre_url'] != url: |
|
agent = Agent( |
|
pd.read_csv(url, index_col=0), |
|
config={"llm": llm} |
|
) |
|
st.session_state['agent'] = agent |
|
st.session_state['pre_url'] = url |
|
|
|
|
|
request = st.text_input( |
|
"Enter your analysis request:", |
|
"Plot a histogram about the distribution of agree, disagree and neutral comments against the topic") |
|
|
|
|
|
if st.button("Analyze"): |
|
if st.session_state['agent'] is not None: |
|
file = st.session_state['agent'].chat(request) |
|
if os.path.exists(file): |
|
st.image(file) |
|
else: |
|
st.info(file) |
|
else: |
|
st.warning("Please select a conversation and load data first.") |