mishiawan commited on
Commit
e09acd2
·
verified ·
1 Parent(s): 3850fe5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -57
app.py CHANGED
@@ -3,67 +3,39 @@ from dotenv import load_dotenv
3
  from groq import Groq
4
  import streamlit as st
5
 
6
- # Load environment variables from .env file
7
  load_dotenv()
8
 
9
- # Ensure that the API key is loaded correctly
10
  GROQ_API_KEY = "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"
11
  client = Groq(api_key =GROQ_API_KEY)
12
- )
13
 
14
- # Custom CSS to style headings and overall appearance
15
- st.markdown("""
16
- <style>
17
- .big-heading {
18
- font-size: 36px;
19
- font-weight: bold;
20
- color: #333;
21
- }
22
- .sub-header {
23
- font-size: 24px;
24
- font-weight: bold;
25
- color: #555;
26
- }
27
- .header {
28
- font-size: 20px;
29
- font-weight: normal;
30
- color: #444;
31
- }
32
- .output-text {
33
- font-size: 18px;
34
- font-weight: normal;
35
- color: #000;
36
- }
37
- </style>
38
- """, unsafe_allow_html=True)
39
 
40
- # Streamlit UI
41
- st.markdown('<p class="big-heading">Python Bot with Groq\'s API</p>', unsafe_allow_html=True)
42
- st.markdown('<p class="sub-header">Interact with an AI Model Powered by Groq</p>', unsafe_allow_html=True)
43
 
44
- # Input Section
45
- st.markdown('<p class="header">Input</p>', unsafe_allow_html=True)
46
- user_input = st.text_input("Enter your question or message below:")
47
-
48
- # Submit button
49
- if st.button("Submit"):
50
- if user_input.strip():
51
- # Output Section
52
- st.markdown('<p class="header">Output</p>', unsafe_allow_html=True)
53
- with st.spinner("Fetching response from the LLM..."):
54
- try:
55
- # Interact with Groq's LLM
56
- chat_completion = client.chat.completions.create(
57
- messages=[
58
- {"role": "user", "content": user_input},
59
- ],
60
- model="llama3-8b-8192",
61
- stream=False,
62
- )
63
- response = chat_completion.choices[0].message.content
64
- st.success("Here is the AI's response:")
65
- st.markdown(f'<p class="output-text">{response}</p>', unsafe_allow_html=True)
66
- except Exception as e:
67
- st.error(f"Error: {e}")
68
- else:
69
- st.warning("Please enter a valid message!")
 
3
  from groq import Groq
4
  import streamlit as st
5
 
6
+ # Load environment variables
7
  load_dotenv()
8
 
 
9
  GROQ_API_KEY = "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"
10
  client = Groq(api_key =GROQ_API_KEY)
 
11
 
12
+ # Streamlit UI
13
+ st.title("Python Bot with Groq's API")
14
+ st.subheader("Interact with an AI Model Powered by Groq")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
+ # Input Section
17
+ st.header("Input")
18
+ user_input = st.text_input("Enter your question or message below:")
19
 
20
+ # Submit button
21
+ if st.button("Submit"):
22
+ if user_input.strip():
23
+ # Output Section
24
+ st.header("Output")
25
+ with st.spinner("Fetching response from the LLM..."):
26
+ try:
27
+ # Interact with Groq's LLM
28
+ chat_completion = client.chat.completions.create(
29
+ messages=[
30
+ {"role": "user", "content": user_input},
31
+ ],
32
+ model="llama3-8b-8192",
33
+ stream=False,
34
+ )
35
+ response = chat_completion.choices[0].message.content
36
+ st.success("Here is the AI's response:")
37
+ st.write(response)
38
+ except Exception as e:
39
+ st.error(f"Error: {e}")
40
+ else:
41
+ st.warning("Please enter a valid message!")