Spaces:
Build error
Build error
SHAMIL SHAHBAZ AWAN commited on
Update app.py
Browse files1 unmodified line234565678917 unmodified lines2728293030313233343536373834394035363738394 unmodified lines4445464748495010 unmodified lines616263646566677172736869707172737475767576777879808182838485868788899091929394959617 unmodified lines1141151161171181191201 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 libraryimport 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") # Ensure this is stored in secrets.jsongroq_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: try: # Initialize the Groq API or Groq model client groq_api = GroqAPI(api_key=groq_api_key) groq_model = GroqModel(model="llama-3.1-8b-instant", groq_api=groq_api) # Load the specific model st.success("Groq model initialized successfully!") st.success("Groq API Key Loaded Successfully!") except Exception as e: st.error(f"Error initializing Groq model: {e}")
# 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 lines st.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 lines except 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: if not groq_model: st.error("Groq model is not initialized. Check for errors in setup.") return # 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 model prompt = 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 inference st.write("Response:", response) # Prepare the request payload payload = { "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 API response = requests.post(api_url, headers=headers, data=json.dumps(payload)) # Check for successful response if 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 lines else: handle_query(data, query)
# Footerfooter = """ <div style='text-align: left; padding: 10px;'> <footer>Created by: Shamil Shahbaz</footer>app.py+33-15