Spaces:
Build error
Build error
SHAMIL SHAHBAZ AWAN commited on
Update app.py
Browse files1 unmodified line23455678916 unmodified lines262728282930312930313233333435363738393536373839414041424322 unmodified lines666768706970727371727374767775767779787980811 unmodified lineimport pandas as pdimport matplotlib.pyplot as pltimport seaborn as snsfrom transformers import AutoModelForCausalLM, AutoTokenizer, pipelinefrom 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 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.")# 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: # Initialize the model and tokenizer using the API key try: model_name = "llama-3.1-8b-instant" # Replace with the correct model name if needed model = 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!") # 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!") except Exception as e: st.error(f"Error initializing model: {e}") st.error(f"Error initializing Groq model: {e}")
def load_file(uploaded_file): """Load the uploaded file."""22 unmodified lines st.error(f"Error generating graph: {e}")
def handle_query(data, query): """Handle user query using the LLM.""" """Handle user query using the Groq model.""" try: if not llm_pipeline: st.error("LLM pipeline is not initialized. Check for errors in setup.") if not groq_model: st.error("Groq model is not initialized. Check for errors in setup.") return prompt = 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']) response = groq_model.generate_text(prompt) # Use the Groq model's method for inference st.write("Response:", response) except Exception as e: st.error(f"Error in LLM processing: {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