Spaces:
Sleeping
Sleeping
SHAMIL SHAHBAZ AWAN
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,8 @@ import streamlit as st
|
|
| 2 |
import pandas as pd
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
import seaborn as sns
|
| 5 |
-
from
|
|
|
|
| 6 |
|
| 7 |
# Configure page
|
| 8 |
st.set_page_config(page_title="Data Augmentation App", layout="wide")
|
|
@@ -25,20 +26,18 @@ st.title("Data Augmentation and Analysis App")
|
|
| 25 |
st.sidebar.title("Upload Your File")
|
| 26 |
st.sidebar.markdown("Supported formats: CSV, Excel")
|
| 27 |
|
| 28 |
-
# Get the
|
| 29 |
-
|
| 30 |
-
if not
|
| 31 |
-
st.error("
|
| 32 |
else:
|
| 33 |
-
# Initialize the model and tokenizer using the API key
|
| 34 |
try:
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
st.success(f"Model {model_name} initialized successfully!")
|
| 40 |
except Exception as e:
|
| 41 |
-
st.error(f"Error initializing model: {e}")
|
| 42 |
|
| 43 |
def load_file(uploaded_file):
|
| 44 |
"""Load the uploaded file."""
|
|
@@ -67,16 +66,16 @@ def generate_graph(data, query):
|
|
| 67 |
st.error(f"Error generating graph: {e}")
|
| 68 |
|
| 69 |
def handle_query(data, query):
|
| 70 |
-
"""Handle user query using the
|
| 71 |
try:
|
| 72 |
-
if not
|
| 73 |
-
st.error("
|
| 74 |
return
|
| 75 |
prompt = f"Given the dataset: {data.to_dict(orient='records')}, answer the following: {query}"
|
| 76 |
-
response =
|
| 77 |
-
st.write("Response:", response
|
| 78 |
except Exception as e:
|
| 79 |
-
st.error(f"Error in
|
| 80 |
|
| 81 |
# Main App
|
| 82 |
uploaded_file = st.sidebar.file_uploader("Upload your file here", type=["csv", "xlsx"])
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
import seaborn as sns
|
| 5 |
+
from groqflow.groqmodel import GroqModel # Ensure this is the correct import for Groq model
|
| 6 |
+
from groqflow.groqapi import GroqAPI # Adjust this based on your Groq library
|
| 7 |
|
| 8 |
# Configure page
|
| 9 |
st.set_page_config(page_title="Data Augmentation App", layout="wide")
|
|
|
|
| 26 |
st.sidebar.title("Upload Your File")
|
| 27 |
st.sidebar.markdown("Supported formats: CSV, Excel")
|
| 28 |
|
| 29 |
+
# Get the Groq API key from secrets
|
| 30 |
+
groq_api_key = st.secrets.get("HUGGINGFACE_API") # Ensure this is stored in secrets.json
|
| 31 |
+
if not groq_api_key:
|
| 32 |
+
st.error("Groq API key not found in secrets.")
|
| 33 |
else:
|
|
|
|
| 34 |
try:
|
| 35 |
+
# Initialize the Groq API or Groq model client
|
| 36 |
+
groq_api = GroqAPI(api_key=groq_api_key)
|
| 37 |
+
groq_model = GroqModel(model="llama-3.1-8b-instant", groq_api=groq_api) # Load the specific model
|
| 38 |
+
st.success("Groq model initialized successfully!")
|
|
|
|
| 39 |
except Exception as e:
|
| 40 |
+
st.error(f"Error initializing Groq model: {e}")
|
| 41 |
|
| 42 |
def load_file(uploaded_file):
|
| 43 |
"""Load the uploaded file."""
|
|
|
|
| 66 |
st.error(f"Error generating graph: {e}")
|
| 67 |
|
| 68 |
def handle_query(data, query):
|
| 69 |
+
"""Handle user query using the Groq model."""
|
| 70 |
try:
|
| 71 |
+
if not groq_model:
|
| 72 |
+
st.error("Groq model is not initialized. Check for errors in setup.")
|
| 73 |
return
|
| 74 |
prompt = f"Given the dataset: {data.to_dict(orient='records')}, answer the following: {query}"
|
| 75 |
+
response = groq_model.generate_text(prompt) # Use the Groq model's method for inference
|
| 76 |
+
st.write("Response:", response)
|
| 77 |
except Exception as e:
|
| 78 |
+
st.error(f"Error in Groq processing: {e}")
|
| 79 |
|
| 80 |
# Main App
|
| 81 |
uploaded_file = st.sidebar.file_uploader("Upload your file here", type=["csv", "xlsx"])
|