itzneeraj06 commited on
Commit
dafb2c2
·
1 Parent(s): 009c4d4

deploy model

Browse files
Files changed (3) hide show
  1. .env +1 -0
  2. app.py +55 -0
  3. requirements.txt +2 -0
.env ADDED
@@ -0,0 +1 @@
 
 
1
+ GROQ_API_KEY=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
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ from groq import Groq
4
+
5
+ # Custom function to load variables from a .env file
6
+ def load_dotenv(filepath=".env"):
7
+ try:
8
+ with open(filepath, "r") as f:
9
+ for line in f:
10
+ line = line.strip()
11
+ # Skip comments and empty lines
12
+ if not line or line.startswith("#"):
13
+ continue
14
+ if "=" in line:
15
+ key, value = line.split("=", 1)
16
+ os.environ.setdefault(key.strip(), value.strip())
17
+ except FileNotFoundError:
18
+ st.error("No .env file found. Please create one with your API key.")
19
+ except Exception as e:
20
+ st.error(f"Error loading .env file: {e}")
21
+
22
+ # Load environment variables from the .env file
23
+ load_dotenv()
24
+
25
+ def main():
26
+ st.title("Samyotech Chatbot")
27
+
28
+ # Fetch API key from environment variables
29
+ groq_api_key = os.environ.get("GROQ_API_KEY")
30
+
31
+ if groq_api_key:
32
+ client = Groq(api_key=groq_api_key)
33
+ st.write("### Chat with LLM")
34
+ user_input = st.text_area("Enter your message:")
35
+
36
+ if st.button("Generate Response"):
37
+ if user_input.strip():
38
+ try:
39
+ response = client.chat.completions.create(
40
+ model="llama-3.3-70b-versatile",
41
+ messages=[
42
+ {"role": "user", "content": user_input}
43
+ ]
44
+ )
45
+ st.write("### Response:")
46
+ st.write(response.choices[0].message.content)
47
+ except Exception as e:
48
+ st.error(f"Error: {e}")
49
+ else:
50
+ st.warning("Please enter a message to generate a response.")
51
+ else:
52
+ st.error("API key not found. Please ensure your .env file contains GROQ_API_KEY.")
53
+
54
+ if __name__ == "__main__":
55
+ main()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit
2
+ groq