DrishtiSharma commited on
Commit
e003b30
Β·
verified Β·
1 Parent(s): b6b9a27

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -24
app.py CHANGED
@@ -20,33 +20,33 @@ from langchain_community.utilities.sql_database import SQLDatabase
20
  from datasets import load_dataset
21
  import tempfile
22
 
23
- # API Key
24
- os.environ["GROQ_API_KEY"] = st.secrets.get("GROQ_API_KEY", "")
25
-
26
- # Initialize LLM
27
- class LLMCallbackHandler(BaseCallbackHandler):
28
- def __init__(self, log_path: Path):
29
- self.log_path = log_path
30
-
31
- def on_llm_start(self, serialized, prompts, **kwargs):
32
- with self.log_path.open("a", encoding="utf-8") as file:
33
- file.write(json.dumps({"event": "llm_start", "text": prompts[0], "timestamp": datetime.now().isoformat()}) + "\n")
34
-
35
- def on_llm_end(self, response: LLMResult, **kwargs):
36
- generation = response.generations[-1][-1].message.content
37
- with self.log_path.open("a", encoding="utf-8") as file:
38
- file.write(json.dumps({"event": "llm_end", "text": generation, "timestamp": datetime.now().isoformat()}) + "\n")
39
-
40
- llm = ChatGroq(
41
- temperature=0,
42
- model_name="groq/llama-3.3-70b-versatile",
43
- max_tokens=500,
44
- callbacks=[LLMCallbackHandler(Path("prompts.jsonl"))],
45
- )
46
-
47
  st.title("SQL-RAG Using CrewAI πŸš€")
48
  st.write("Analyze datasets using natural language queries powered by SQL and CrewAI.")
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  # Initialize session state for data persistence
51
  if "df" not in st.session_state:
52
  st.session_state.df = None
 
20
  from datasets import load_dataset
21
  import tempfile
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  st.title("SQL-RAG Using CrewAI πŸš€")
24
  st.write("Analyze datasets using natural language queries powered by SQL and CrewAI.")
25
 
26
+ # Initialize LLM
27
+ llm = None
28
+
29
+ # Model Selection
30
+ model_choice = st.radio("Select LLM", ["GPT-4o", "llama-3.3-70b"], index=0, horizontal=True)
31
+
32
+
33
+ # API Key Validation and LLM Initialization
34
+ groq_api_key = os.getenv("GROQ_API_KEY")
35
+ openai_api_key = os.getenv("OPENAI_API_KEY")
36
+
37
+ if model_choice == "llama-3.3-70b":
38
+ if not groq_api_key:
39
+ st.error("Groq API key is missing. Please set the GROQ_API_KEY environment variable.")
40
+ llm = None
41
+ else:
42
+ llm = ChatGroq(groq_api_key=groq_api_key, model="groq/llama-3.3-70b-versatile")
43
+ elif model_choice == "GPT-4o":
44
+ if not openai_api_key:
45
+ st.error("OpenAI API key is missing. Please set the OPENAI_API_KEY environment variable.")
46
+ llm = None
47
+ else:
48
+ llm = ChatOpenAI(api_key=openai_api_key, model="gpt-4o")
49
+
50
  # Initialize session state for data persistence
51
  if "df" not in st.session_state:
52
  st.session_state.df = None