Spaces:
Build error
Build error
SHAMIL SHAHBAZ AWAN commited on
Update app.py
Browse files1 unmodified line2345678917 unmodified lines2728293031323334353637383940414243444 unmodified lines49505152535410 unmodified lines65666768697071727374757677787917 unmodified lines9798991001011021 unmodified lineimport pandas as pdimport matplotlib.pyplot as pltimport seaborn as snsfrom groqflow.groqmodel import GroqModel # Ensure this is the correct import for Groq modelfrom groqflow.groqapi import GroqAPI # Adjust this based on your Groq library# Configure pagest.set_page_config(page_title="Data Augmentation App", layout="wide")17 unmodified linesst.sidebar.markdown("Supported formats: CSV, Excel")# Get the Groq API key from secretsgroq_api_key = st.secrets.get("HUGGINGFACE_KEY") # Ensure this is stored in secrets.jsonif not groq_api_key:st.error("Groq API key not found in secrets.")else:try:# Initialize the Groq API or Groq model clientgroq_api = GroqAPI(api_key=groq_api_key)groq_model = GroqModel(model="llama-3.1-8b-instant", groq_api=groq_api) # Load the specific modelst.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'):4 unmodified linesst.error("Unsupported file format. Please upload a CSV or Excel file.")return Nonedef generate_graph(data, query):"""Generate a graph based on user query."""try:10 unmodified linesexcept 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.")returnprompt = 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 inferencest.write("Response:", response)except Exception as e:st.error(f"Error in Groq processing: {e}")17 unmodified lineselse:handle_query(data, query)footer = """<div style='text-align: left; padding: 10px;'><footer>Created by: Shamil Shahbaz</footer>1 unmodified line2345678917 unmodified lines272829303132333435363738394 unmodified lines4445464748495010 unmodified lines61626364656667686970717273747576777879808182838485868788899091929394959617 unmodified lines1141151161171181191201 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")17 unmodified linesst.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."""if uploaded_file.name.endswith('.csv'):4 unmodified linesst.error("Unsupported file format. Please upload a CSV or Excel file.")return None# Function to generate graph based on user querydef generate_graph(data, query):"""Generate a graph based on user query."""try:10 unmodified linesexcept Exception as e:st.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}")17 unmodified lineselse:handle_query(data, query)# Footerfooter = """<div style='text-align: left; padding: 10px;'><footer>Created by: Shamil Shahbaz</footer>
app.py+33-15