SHAMIL SHAHBAZ AWAN commited on
Commit
15dd5f2
·
verified ·
1 Parent(s): 044e524

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -18
app.py CHANGED
@@ -2,7 +2,8 @@ import streamlit as st
2
  import pandas as pd
3
  import matplotlib.pyplot as plt
4
  import seaborn as sns
5
- from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
 
6
 
7
  # Configure page
8
  st.set_page_config(page_title="Data Augmentation App", layout="wide")
@@ -25,20 +26,18 @@ st.title("Data Augmentation and Analysis App")
25
  st.sidebar.title("Upload Your File")
26
  st.sidebar.markdown("Supported formats: CSV, Excel")
27
 
28
- # Get the Hugging Face API key from secrets
29
- hf_api_key = st.secrets.get("HUGGINGFACE_KEY")
30
- if not hf_api_key:
31
- st.error("Hugging Face API key not found in secrets.")
32
  else:
33
- # Initialize the model and tokenizer using the API key
34
  try:
35
- model_name = "llama-3.1-8b-instant" # Replace with the correct model name if needed
36
- model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=hf_api_key)
37
- tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=hf_api_key)
38
- llm_pipeline = pipeline("text-generation", model=model, tokenizer=tokenizer)
39
- st.success(f"Model {model_name} initialized successfully!")
40
  except Exception as e:
41
- st.error(f"Error initializing model: {e}")
42
 
43
  def load_file(uploaded_file):
44
  """Load the uploaded file."""
@@ -67,16 +66,16 @@ def generate_graph(data, query):
67
  st.error(f"Error generating graph: {e}")
68
 
69
  def handle_query(data, query):
70
- """Handle user query using the LLM."""
71
  try:
72
- if not llm_pipeline:
73
- st.error("LLM pipeline is not initialized. Check for errors in setup.")
74
  return
75
  prompt = f"Given the dataset: {data.to_dict(orient='records')}, answer the following: {query}"
76
- response = llm_pipeline(prompt, max_length=200, num_return_sequences=1)
77
- st.write("Response:", response[0]['generated_text'])
78
  except Exception as e:
79
- st.error(f"Error in LLM processing: {e}")
80
 
81
  # Main App
82
  uploaded_file = st.sidebar.file_uploader("Upload your file here", type=["csv", "xlsx"])
 
2
  import pandas as pd
3
  import matplotlib.pyplot as plt
4
  import seaborn as sns
5
+ from groqflow.groqmodel import GroqModel # Ensure this is the correct import for Groq model
6
+ from groqflow.groqapi import GroqAPI # Adjust this based on your Groq library
7
 
8
  # Configure page
9
  st.set_page_config(page_title="Data Augmentation App", layout="wide")
 
26
  st.sidebar.title("Upload Your File")
27
  st.sidebar.markdown("Supported formats: CSV, Excel")
28
 
29
+ # Get the Groq API key from secrets
30
+ groq_api_key = st.secrets.get("HUGGINGFACE_API") # Ensure this is stored in secrets.json
31
+ if not groq_api_key:
32
+ st.error("Groq API key not found in secrets.")
33
  else:
 
34
  try:
35
+ # Initialize the Groq API or Groq model client
36
+ groq_api = GroqAPI(api_key=groq_api_key)
37
+ groq_model = GroqModel(model="llama-3.1-8b-instant", groq_api=groq_api) # Load the specific model
38
+ st.success("Groq model initialized successfully!")
 
39
  except Exception as e:
40
+ st.error(f"Error initializing Groq model: {e}")
41
 
42
  def load_file(uploaded_file):
43
  """Load the uploaded file."""
 
66
  st.error(f"Error generating graph: {e}")
67
 
68
  def handle_query(data, query):
69
+ """Handle user query using the Groq model."""
70
  try:
71
+ if not groq_model:
72
+ st.error("Groq model is not initialized. Check for errors in setup.")
73
  return
74
  prompt = f"Given the dataset: {data.to_dict(orient='records')}, answer the following: {query}"
75
+ response = groq_model.generate_text(prompt) # Use the Groq model's method for inference
76
+ st.write("Response:", response)
77
  except Exception as e:
78
+ st.error(f"Error in Groq processing: {e}")
79
 
80
  # Main App
81
  uploaded_file = st.sidebar.file_uploader("Upload your file here", type=["csv", "xlsx"])