Spaces:
Build error
Build error
SHAMIL SHAHBAZ AWAN commited on
Update app.py
Browse files1 unmodified line234567816 unmodified lines252627282930313233343536373839404142434422 unmodified lines676869707172737475767778798081821 unmodified lineimport pandas as pdimport matplotlib.pyplot as pltimport seaborn as snsfrom transformers import AutoModelForCausalLM, AutoTokenizer, pipeline# 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 Hugging Face API key from secretshf_api_key = st.secrets.get("HUGGINGFACE_KEY")if not hf_api_key:st.error("Hugging Face API key not found in secrets.")else:# Initialize the model and tokenizer using the API keytry:model_name = "llama-3.1-8b-instant" # Replace with the correct model name if neededmodel = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=hf_api_key)tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=hf_api_key)llm_pipeline = pipeline("text-generation", model=model, tokenizer=tokenizer)st.success(f"Model {model_name} initialized successfully!")except Exception as e:st.error(f"Error initializing model: {e}")def load_file(uploaded_file):"""Load the uploaded file."""22 unmodified linesst.error(f"Error generating graph: {e}")def handle_query(data, query):"""Handle user query using the LLM."""try:if not llm_pipeline:st.error("LLM pipeline is not initialized. Check for errors in setup.")returnprompt = f"Given the dataset: {data.to_dict(orient='records')}, answer the following: {query}"response = llm_pipeline(prompt, max_length=200, num_return_sequences=1)st.write("Response:", response[0]['generated_text'])except Exception as e:st.error(f"Error in LLM processing: {e}")# Main Appuploaded_file = st.sidebar.file_uploader("Upload your file here", type=["csv", "xlsx"])1 unmodified line2345678916 unmodified lines26272829303132333435363738394041424322 unmodified lines666768697071727374757677787980811 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")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_API") # 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."""22 unmodified linesst.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}")# Main Appuploaded_file = st.sidebar.file_uploader("Upload your file here", type=["csv", "xlsx"])
app.py+17-18