Spaces:
Build error
Build error
SHAMIL SHAHBAZ AWAN commited on
Update app.py
Browse files1 unmodified line2345678916 unmodified lines2627282930313233343536373823 unmodified lines626364656667686970717273747576777879808182838485868788899091929394959612 unmodified lines1091101111121131141151161171181 unmodified lineimport pandas as pdimport matplotlib.pyplot as pltimport seaborn as snsimport jsonimport requests# Configure pagest.set_page_config(page_title="Data Augmentation App", layout="wide")16 unmodified linesst.sidebar.title("Upload Your File")st.sidebar.markdown("Supported formats: CSV, Excel")# Get the Groq API key from secretsgroq_api_key = st.secrets.get("HUGGINGFACE_KEY") # Fetch Groq API key stored in secrets.jsonif not groq_api_key:st.error("Groq API key not found in secrets.")else:st.success("Groq API Key Loaded Successfully!")# Function to load data from file (CSV/Excel)def load_file(uploaded_file):"""Load the uploaded file."""23 unmodified linesst.error(f"Error generating graph: {e}")# Function to handle user queries using the Groq modeldef handle_query(data, query):"""Handle user query using the Groq model."""try:# Groq API URL and Headers (adjust the URL to match your Groq API endpoint)api_url = "https://api.groq.com/v1/models/llama-3.1-8b-instant/generate"headers = {"Authorization": f"Bearer {groq_api_key}","Content-Type": "application/json",}# Create prompt for the modelprompt = f"Given the dataset: {data.to_dict(orient='records')}, answer the following: {query}"# Prepare the request payloadpayload = {"inputs": prompt,"max_tokens": 150, # Adjust the response length if necessary"temperature": 0.7 # Adjust temperature for randomness in response}# Send POST request to Groq APIresponse = requests.post(api_url, headers=headers, data=json.dumps(payload))# Check for successful responseif response.status_code == 200:response_json = response.json()st.write("Response from Groq Model:", response_json.get("generated_text", "No response"))else:st.error(f"Error querying Groq model: {response.status_code} - {response.text}")except Exception as e:st.error(f"Error in Groq processing: {e}")12 unmodified linesst.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)# Footerfooter = """1 unmodified line23456789101112131415161716 unmodified lines3435363738394041424344454647484923 unmodified lines73747576777879808182838485868788899012 unmodified lines1031041051061071081091101 unmodified lineimport pandas as pdimport matplotlib.pyplot as pltimport seaborn as snsimport osfrom groq import Groq# Check if openpyxl is installedtry:import openpyxlexcept ImportError:st.error("openpyxl module is required to read Excel files. Attempting to install...")os.system('pip install openpyxl')st.success("openpyxl installed successfully. Please restart the app.")# Configure pagest.set_page_config(page_title="Data Augmentation App", layout="wide")16 unmodified linesst.sidebar.title("Upload Your File")st.sidebar.markdown("Supported formats: CSV, Excel")# Fetch Groq API key from Streamlit secretsgroq_api_key = st.secrets.get("HUGGINGFACE_KEY") # Fetch Groq API key stored in secrets.jsonif not groq_api_key:st.error("Groq API key not found in secrets.")else:st.success("Groq API Key Loaded Successfully!")# Initialize Groq clientclient = Groq(api_key=groq_api_key)# Function to load data from file (CSV/Excel)def load_file(uploaded_file):"""Load the uploaded file."""23 unmodified linesst.error(f"Error generating graph: {e}")# Function to handle user queries using the Groq modeldef handle_query(query):"""Handle user query using the Groq model."""try:# Send user query to Groq model using Groq SDKchat_completion = client.chat.completions.create(messages=[{"role": "user", "content": query}],model="llama3-8b-8192", # Model name as per your Groq model)# Display the responsest.write("Response from Groq Model:", chat_completion.choices[0].message.content)except Exception as e:st.error(f"Error in Groq processing: {e}")12 unmodified linesst.write(data)elif "graph" in query.lower():generate_graph(data, query)else:handle_query(query) # Use Groq model for query processing# Footerfooter = """
app.py+23-31