Data-Excel / app.py
SHAMIL SHAHBAZ AWAN
Update app.py
b6ebb13 verified
raw
history blame
3.84 kB
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from groqflow.groqmodel import GroqModel # Ensure this is the correct import for Groq model
from groqflow.groqapi import GroqAPI # Adjust this based on your Groq library
# Configure page
st.set_page_config(page_title="Data Augmentation App", layout="wide")
st.markdown(
f"""
<style>
.reportview-container {{
background: url("https://cdn.pixabay.com/photo/2016/06/02/02/33/triangles-1430105_1280.png");
background-size: cover;
}}
footer {{
text-align: left;
}}
</style>
""",
unsafe_allow_html=True,
)
st.title("Data Augmentation and Analysis App")
st.sidebar.title("Upload Your File")
st.sidebar.markdown("Supported formats: CSV, Excel")
# Get the Groq API key from secrets
groq_api_key = st.secrets.get("HUGGINGFACE_KEY") # Ensure this is stored in secrets.json
if not groq_api_key:
st.error("Groq API key not found in secrets.")
else:
try:
# Initialize the Groq API or Groq model client
groq_api = GroqAPI(api_key=groq_api_key)
groq_model = GroqModel(model="llama-3.1-8b-instant", groq_api=groq_api) # Load the specific model
st.success("Groq model initialized successfully!")
except Exception as e:
st.error(f"Error initializing Groq model: {e}")
def load_file(uploaded_file):
"""Load the uploaded file."""
if uploaded_file.name.endswith('.csv'):
return pd.read_csv(uploaded_file)
elif uploaded_file.name.endswith('.xlsx'):
return pd.read_excel(uploaded_file)
else:
st.error("Unsupported file format. Please upload a CSV or Excel file.")
return None
def generate_graph(data, query):
"""Generate a graph based on user query."""
try:
fig, ax = plt.subplots(figsize=(10, 6))
if "correlation" in query.lower():
sns.heatmap(data.corr(), annot=True, cmap="coolwarm", ax=ax)
st.pyplot(fig)
elif "histogram" in query.lower():
column = st.selectbox("Select a column for the histogram", data.columns)
sns.histplot(data[column], kde=True, ax=ax)
st.pyplot(fig)
else:
st.error("Unsupported graph type. Try asking for a correlation matrix or histogram.")
except Exception as e:
st.error(f"Error generating graph: {e}")
def handle_query(data, query):
"""Handle user query using the Groq model."""
try:
if not groq_model:
st.error("Groq model is not initialized. Check for errors in setup.")
return
prompt = f"Given the dataset: {data.to_dict(orient='records')}, answer the following: {query}"
response = groq_model.generate_text(prompt) # Use the Groq model's method for inference
st.write("Response:", response)
except Exception as e:
st.error(f"Error in Groq processing: {e}")
# Main App
uploaded_file = st.sidebar.file_uploader("Upload your file here", type=["csv", "xlsx"])
if uploaded_file:
data = load_file(uploaded_file)
if data is not None:
st.write("Dataset Preview")
st.dataframe(data)
query = st.text_area("Ask your question about the dataset")
if query:
if "table" in query.lower():
st.write("Table Preview")
st.write(data)
elif "graph" in query.lower():
generate_graph(data, query)
elif "predict" in query.lower():
st.write("Prediction functionality is in progress.")
else:
handle_query(data, query)
footer = """
<div style='text-align: left; padding: 10px;'>
<footer>Created by: Shamil Shahbaz</footer>
</div>
"""
st.markdown(footer, unsafe_allow_html=True)