Spaces:
Build error
Build error
SHAMIL SHAHBAZ AWAN commited on
Update app.py
Browse files1 unmodified line2345656789101112131415161716 unmodified lines343536293738394041424344454647484923 unmodified lines7374756576777868697071727374757679808182838478798081828385868785868788899091929388899012 unmodified lines1031041051121131061151071081091101 unmodified lineimport pandas as pdimport matplotlib.pyplot as pltimport seaborn as snsimport jsonimport requestsimport 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")
# Get the Groq API key from secrets# 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 lines st.error(f"Error generating graph: {e}")
# Function to handle user queries using the Groq modeldef handle_query(data, query):def handle_query(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 model prompt = f"Given the dataset: {data.to_dict(orient='records')}, answer the following: {query}" # Send user query to Groq model using Groq SDK chat_completion = client.chat.completions.create( messages=[{"role": "user", "content": query}], model="llama3-8b-8192", # Model name as per your Groq model ) # 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 } # Display the response st.write("Response from Groq Model:", chat_completion.choices[0].message.content) # 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}")
12 unmodified lines st.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) handle_query(query) # Use Groq model for query processing
# Footerfooter = """app.py+23-31