Tanseer45203 commited on
Commit
557b471
·
verified ·
1 Parent(s): b98d0b4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from groq import Groq
4
+ from dotenv import load_dotenv
5
+
6
+ # Load environment variables from .env file
7
+ load_dotenv()
8
+
9
+ # Ensure your environment variable for the API key is set
10
+ api_key = os.getenv("GROQ_API_KEY")
11
+ if not api_key:
12
+ st.error("API key is not set. Please set your GROQ_API_KEY environment variable.")
13
+ st.stop()
14
+
15
+ # Initialize Groq client with API key
16
+ client = Groq(api_key=api_key)
17
+
18
+ # Streamlit interface
19
+ st.title("General Knowledge Chatbot")
20
+
21
+ # Chat history container
22
+ chat_history = st.container()
23
+ user_input = st.text_input("Ask me anything:")
24
+
25
+ if user_input:
26
+ # Add user message to chat history
27
+ with chat_history:
28
+ st.write(f"**You:** {user_input}")
29
+
30
+ # Chat completion request to Groq API
31
+ chat_completion = client.chat.completions.create(
32
+ messages=[
33
+ {"role": "user", "content": user_input},
34
+ ],
35
+ model="llama-3.3-70b-versatile", # Use the model that suits your needs
36
+ )
37
+
38
+ # Get the response from the API
39
+ response = chat_completion.choices[0].message.content
40
+
41
+ # Display response
42
+ with chat_history:
43
+ st.write(f"**Chatbot:** {response}")