ibrahim313 commited on
Commit
c209a82
β€’
1 Parent(s): e5fa455

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -0
app.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from streamlit.components.v1 import html
3
+ import os
4
+ from groq import Groq
5
+
6
+ # Initialize Groq Client
7
+ client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
8
+
9
+ # Set the title of the app
10
+ st.title("AI Chatbot with Groq LLaMA Model")
11
+
12
+ # Custom CSS for a professional look
13
+ css = """
14
+ <style>
15
+ body {
16
+ background-color: #f0f2f6;
17
+ font-family: 'Arial', sans-serif;
18
+ }
19
+ .stTextInput, .stButton {
20
+ margin-top: 20px;
21
+ }
22
+ .custom-box {
23
+ padding: 20px;
24
+ background-color: #ffffff;
25
+ border-radius: 8px;
26
+ box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
27
+ }
28
+ .error-msg {
29
+ color: red;
30
+ font-weight: bold;
31
+ }
32
+ </style>
33
+ """
34
+
35
+ html(css)
36
+
37
+ st.markdown(
38
+ """
39
+ <div class='custom-box'>
40
+ <h2>Ask anything about Data Science</h2>
41
+ <p>Powered by Groq LLaMA 3.1 Model πŸš€</p>
42
+ </div>
43
+ """, unsafe_allow_html=True
44
+ )
45
+
46
+ # Input for user queries
47
+ user_input = st.text_input("Ask your question here:")
48
+
49
+ # Function to handle Groq API call
50
+ def get_groq_response(query):
51
+ try:
52
+ chat_completion = client.chat.completions.create(
53
+ messages=[{"role": "user", "content": query}],
54
+ model="llama-3.1-70b-versatile",
55
+ )
56
+ return chat_completion.choices[0].message.content
57
+ except Exception as e:
58
+ return f"An error occurred: {str(e)}"
59
+
60
+ # Submit button for the chatbot
61
+ if st.button("Submit"):
62
+ if user_input:
63
+ with st.spinner("Fetching response..."):
64
+ response = get_groq_response(user_input)
65
+ st.success(response)
66
+ else:
67
+ st.error("Please enter a question!")
68
+
69
+ # Copy Button for User to easily copy the result
70
+ if response:
71
+ st.code(response)
72
+ st.button("Copy to clipboard", on_click=st.experimental_rerun)