Spaces:
Sleeping
Sleeping
File size: 3,588 Bytes
417d8a6 552b8ff 417d8a6 552b8ff 417d8a6 552b8ff 417d8a6 | 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 105 | import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
try:
from groqflow.groqmodel import GroqModel
except ImportError as e:
st.error(f"Failed to import GroqModel. Please ensure all dependencies are installed correctly. Error: {e}")
# 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")
# Load Groq API key from secrets
try:
groq_api_key = st.secrets["HUGGINGFACE_KEY"]
groq_model = GroqModel("llama3-8b-8192", api_key=groq_api_key)
except KeyError:
st.error("API key not found in secrets. Please configure your `HUGGINGFACE_KEY` in Streamlit secrets.")
except Exception as e:
st.error(f"Error initializing GroqModel: {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 Groq API."""
try:
if not groq_model:
st.error("GroqModel 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(prompt)
st.write("Response:", response)
except Exception as e:
st.error(f"Error in LLM 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)
|