ShubhamMhaske commited on
Commit
dc0a3a2
Β·
verified Β·
1 Parent(s): 1bbb715

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -11
app.py CHANGED
@@ -1,29 +1,75 @@
1
  import streamlit as st
2
  from groq import Groq
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  # Streamlit App
5
- st.title("Q&A Application with Groq API")
6
  st.write("Ask a question and get a response using Groq's AI model!")
7
 
8
  # Input for API key
9
- api_key = st.text_input("Enter your GROQ API Key:", type="password")
10
 
11
  # Check if API key is provided
12
  if not api_key:
13
- st.warning("Please enter your GROQ API Key to proceed.")
14
  else:
15
  # Initialize the Groq client
16
  try:
17
  client = Groq(api_key=api_key)
18
- st.success("GROQ API Key successfully set!")
19
  except Exception as e:
20
- st.error(f"Error initializing Groq client: {str(e)}")
21
 
22
  # Input prompt from the user
23
- user_input = st.text_input("Enter your question:", "")
24
 
25
  # Button to trigger the API call
26
- if st.button("Get Answer"):
27
  if user_input.strip():
28
  try:
29
  # API call to Groq
@@ -34,13 +80,17 @@ else:
34
  # Extracting the response
35
  response = chat_completion.choices[0].message.content
36
  # Display the response
37
- st.subheader("Response:")
38
  st.write(response)
39
  except Exception as e:
40
- st.error(f"Error: {str(e)}")
41
  else:
42
- st.warning("Please enter a valid question.")
43
 
44
  # Footer
45
  st.markdown("---")
46
- st.markdown("**Powered by Groq AI**")
 
 
 
 
 
1
  import streamlit as st
2
  from groq import Groq
3
 
4
+ # Custom CSS for styling
5
+ def add_custom_css():
6
+ st.markdown(
7
+ """
8
+ <style>
9
+ body {
10
+ background-color: #f7f9fc;
11
+ color: #333;
12
+ font-family: 'Arial', sans-serif;
13
+ }
14
+ .main > div {
15
+ background: white;
16
+ border-radius: 10px;
17
+ padding: 20px;
18
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
19
+ }
20
+ input[type="password"], input[type="text"] {
21
+ border: 2px solid #ccc;
22
+ border-radius: 5px;
23
+ padding: 10px;
24
+ margin-bottom: 10px;
25
+ width: 100%;
26
+ }
27
+ button {
28
+ background-color: #4CAF50;
29
+ color: white;
30
+ padding: 10px 20px;
31
+ border: none;
32
+ border-radius: 5px;
33
+ cursor: pointer;
34
+ font-size: 16px;
35
+ }
36
+ button:hover {
37
+ background-color: #45a049;
38
+ }
39
+ .stMarkdown {
40
+ font-size: 16px;
41
+ }
42
+ </style>
43
+ """,
44
+ unsafe_allow_html=True
45
+ )
46
+
47
+ # Add custom CSS
48
+ add_custom_css()
49
+
50
  # Streamlit App
51
+ st.title("✨ Q&A Application with Groq API ✨")
52
  st.write("Ask a question and get a response using Groq's AI model!")
53
 
54
  # Input for API key
55
+ api_key = st.text_input("πŸ”‘ Enter your GROQ API Key:", type="password")
56
 
57
  # Check if API key is provided
58
  if not api_key:
59
+ st.warning("⚠️ Please enter your GROQ API Key to proceed.")
60
  else:
61
  # Initialize the Groq client
62
  try:
63
  client = Groq(api_key=api_key)
64
+ st.success("βœ… GROQ API Key successfully set!")
65
  except Exception as e:
66
+ st.error(f"❌ Error initializing Groq client: {str(e)}")
67
 
68
  # Input prompt from the user
69
+ user_input = st.text_input("πŸ’¬ Enter your question:", "")
70
 
71
  # Button to trigger the API call
72
+ if st.button("πŸš€ Get Answer"):
73
  if user_input.strip():
74
  try:
75
  # API call to Groq
 
80
  # Extracting the response
81
  response = chat_completion.choices[0].message.content
82
  # Display the response
83
+ st.subheader("πŸ€– Response:")
84
  st.write(response)
85
  except Exception as e:
86
+ st.error(f"❌ Error: {str(e)}")
87
  else:
88
+ st.warning("⚠️ Please enter a valid question.")
89
 
90
  # Footer
91
  st.markdown("---")
92
+ st.markdown(
93
+ "<div style='text-align: center;'>✨ <strong>Powered by Groq AI</strong> ✨</div>",
94
+ unsafe_allow_html=True
95
+ )
96
+