SHAMIL SHAHBAZ AWAN commited on
Commit
417d8a6
·
verified ·
1 Parent(s): 64cfddd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -0
app.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+ import seaborn as sns
5
+ from groqflow.groqmodel import GroqModel
6
+
7
+ # Configure page
8
+ st.set_page_config(page_title="Data Augmentation App", layout="wide")
9
+ st.markdown(
10
+ f"""
11
+ <style>
12
+ .reportview-container {{
13
+ background: url("https://cdn.pixabay.com/photo/2016/06/02/02/33/triangles-1430105_1280.png");
14
+ background-size: cover;
15
+ }}
16
+ footer {{
17
+ text-align: left;
18
+ }}
19
+ </style>
20
+ """,
21
+ unsafe_allow_html=True,
22
+ )
23
+
24
+ st.title("Data Augmentation and Analysis App")
25
+ st.sidebar.title("Upload Your File")
26
+ st.sidebar.markdown("Supported formats: CSV, Excel")
27
+
28
+ # Load Groq API key from secrets
29
+ groq_api_key = st.secrets["HUGGINGFACE_KEY"]
30
+
31
+ # Load Groq model
32
+ groq_model = GroqModel("llama3-8b-8192", api_key=groq_api_key)
33
+
34
+ def load_file(uploaded_file):
35
+ """Load the uploaded file."""
36
+ if uploaded_file.name.endswith('.csv'):
37
+ return pd.read_csv(uploaded_file)
38
+ elif uploaded_file.name.endswith('.xlsx'):
39
+ return pd.read_excel(uploaded_file)
40
+ else:
41
+ st.error("Unsupported file format. Please upload a CSV or Excel file.")
42
+ return None
43
+
44
+ def generate_graph(data, query):
45
+ """Generate a graph based on user query."""
46
+ try:
47
+ fig, ax = plt.subplots(figsize=(10, 6))
48
+ if "correlation" in query.lower():
49
+ sns.heatmap(data.corr(), annot=True, cmap="coolwarm", ax=ax)
50
+ st.pyplot(fig)
51
+ elif "histogram" in query.lower():
52
+ column = st.selectbox("Select a column for the histogram", data.columns)
53
+ sns.histplot(data[column], kde=True, ax=ax)
54
+ st.pyplot(fig)
55
+ else:
56
+ st.error("Unsupported graph type. Try asking for a correlation matrix or histogram.")
57
+ except Exception as e:
58
+ st.error(f"Error generating graph: {e}")
59
+
60
+ def handle_query(data, query):
61
+ """Handle user query using Groq API."""
62
+ try:
63
+ prompt = f"Given the dataset: {data.to_dict(orient='records')}, answer the following: {query}"
64
+ response = groq_model.generate(prompt)
65
+ st.write("Response:", response)
66
+ except Exception as e:
67
+ st.error(f"Error in LLM processing: {e}")
68
+
69
+ # Main App
70
+ uploaded_file = st.sidebar.file_uploader("Upload your file here", type=["csv", "xlsx"])
71
+ if uploaded_file:
72
+ data = load_file(uploaded_file)
73
+ if data is not None:
74
+ st.write("Dataset Preview")
75
+ st.dataframe(data)
76
+
77
+ query = st.text_area("Ask your question about the dataset")
78
+ if query:
79
+ if "table" in query.lower():
80
+ st.write("Table Preview")
81
+ st.write(data)
82
+ elif "graph" in query.lower():
83
+ generate_graph(data, query)
84
+ elif "predict" in query.lower():
85
+ st.write("Prediction functionality is in progress.")
86
+ else:
87
+ handle_query(data, query)
88
+
89
+ footer = """
90
+ <div style='text-align: left; padding: 10px;'>
91
+ <footer>Created by: Shamil Shahbaz</footer>
92
+ </div>
93
+ """
94
+ st.markdown(footer, unsafe_allow_html=True)