Spaces:
Build error
Build error
SHAMIL SHAHBAZ AWAN commited on
Update app.py
Browse files1 unmodified line2345678910111216 unmodified lines293031323334353637383940414222 unmodified lines65666768697071727374757677781 unmodified lineimport pandas as pdimport matplotlib.pyplot as pltimport seaborn as snstry:from groqflow.groqmodel import GroqModelexcept ImportError as e:st.error(f"Failed to import GroqModel. Please ensure all dependencies are installed correctly. Error: {e}")# 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")# Load Groq API key from secretstry:groq_api_key = st.secrets["HUGGINGFACE_KEY"]groq_model = GroqModel("llama3-8b-8192", api_key=groq_api_key)except KeyError:st.error("API key not found in secrets. Please configure your `HUGGINGFACE_KEY` in Streamlit secrets.")except Exception as e:st.error(f"Error initializing GroqModel: {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 Groq API."""try:if not groq_model:st.error("GroqModel 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(prompt)st.write("Response:", response)except Exception as e:st.error(f"Error in LLM processing: {e}")1 unmodified line234567816 unmodified lines252627282930313233343536373839404142434422 unmodified lines67686970717273747576777879801 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 = "llama3-70b-8192" # 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}")
app.py+20-18