THE-RAJ commited on
Commit
955a969
1 Parent(s): 543de7a

Upload 3 files

Browse files
Files changed (3) hide show
  1. .env +1 -0
  2. app.py +138 -0
  3. requirements.txt +3 -0
.env ADDED
@@ -0,0 +1 @@
 
 
1
+ groq_api_key="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"
app.py ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from groq import Groq
4
+ from dotenv import load_dotenv
5
+
6
+ load_dotenv()
7
+ groq_api_key = os.getenv("groq_api_key")
8
+
9
+ st.sidebar.title(":white[_Tailor_]")
10
+ prompt = st.sidebar.title(":red[_System Prompt:_] ")
11
+ model = st.sidebar.selectbox(
12
+ 'Choose a model', ['Llama3-8b-8192', 'Llama3-70b-8192','Mixtral-8x7b-32768','Gemma-7b-It']
13
+ )
14
+
15
+ # Groq client
16
+ client = Groq(api_key = groq_api_key)
17
+
18
+ # Streamlit Interface
19
+ st.title("🗨️ LLMS :red[Interaction] - :blue[By Raj]")
20
+
21
+ # Define the CSS for the animation
22
+ animation_css = """
23
+ <style>
24
+ @keyframes fadeInLeft {
25
+ from {
26
+ opacity: 0;
27
+ transform: translateX(-50px);
28
+ }
29
+ to {
30
+ opacity: 1;
31
+ transform: translateX(0);
32
+ }
33
+ }
34
+
35
+ @keyframes fadeInRight {
36
+ from {
37
+ opacity: 0;
38
+ transform: translateX(50px);
39
+ }
40
+ to {
41
+ opacity: 1;
42
+ transform: translateX(0);
43
+ }
44
+ }
45
+
46
+ .fadeInLeft {
47
+ animation: fadeInLeft 2s ease-out;
48
+ }
49
+
50
+ .fadeInRight {
51
+ animation: fadeInRight 2s ease-out;
52
+ }
53
+ </style>
54
+ """
55
+
56
+ # Apply the animation to your text
57
+ animated_text = """
58
+ <div class="fadeInLeft">Welcome to the LLMS Interaction web app!</div>
59
+ <div class="fadeInRight">This app allows you to interact with the LLMS AI model. To use the app, follow these steps:</div>
60
+ <div class="fadeInLeft">1. Enter your question in the text input box.</div>
61
+ <div class="fadeInRight">2. Click the 'Submit' button to send your question to the AI model.</div>
62
+ <div class="fadeInLeft">3. The response will be displayed below the text input box.</div>
63
+ <div class="fadeInRight">4. You can view the history of your queries and responses in the sidebar.</div>
64
+ <div class="fadeInLeft">5. To view the details of a specific query, click on the corresponding button in the sidebar.</div>
65
+ <div class="fadeInRight">Please note that this web app is super fast and utilizes custom api integration to fetch responses.</div>
66
+ <div class="fadeInLeft">Try it</div>
67
+ """
68
+
69
+ # Combine the CSS and the text
70
+ final_output = animation_css + animated_text
71
+
72
+ # Display using st.markdown
73
+ st.markdown(final_output, unsafe_allow_html=True)
74
+
75
+ # Initialize sessesion state for history
76
+ if "history" not in st.session_state:
77
+ st.session_state.history = []
78
+
79
+ user_input = st.text_input("Enter your question: ", "")
80
+
81
+ if st.button("Submit"):
82
+ chat_completion = client.chat.completions.create(
83
+ messages=[
84
+ {
85
+ "role" : "user",
86
+ "content" : user_input,
87
+ }
88
+ ],
89
+ model = model,
90
+ )
91
+ # Store the query and response in history
92
+ response = chat_completion.choices[0].message.content
93
+ st.session_state.history.append({"query" : user_input, "response" : response})
94
+
95
+ # Display the response
96
+ st.markdown(f'<div class="response-box">{response}</div>', unsafe_allow_html=True)
97
+
98
+ # Display history
99
+ st.sidebar.title(":rainbow[Memory]")
100
+ for i, entry in enumerate(st.session_state.history):
101
+ if st.sidebar.button(f'Query {i+1}: {entry["query"]}'):
102
+ st.markdown(f'<div class="response-box">{entry["response"]}</div>', unsafe_allow_html=True)
103
+
104
+ # Add a footer with fade-in animation
105
+ footer = """
106
+ <style>
107
+ .my-footer {
108
+ position: fixed;
109
+ bottom: -50px;
110
+ left: 0;
111
+ width: 100%;
112
+ background-color: black;
113
+ text-align: center;
114
+ padding: 10px;
115
+ font-size: 20px; /* Increased the font size to medium */
116
+ color: white;
117
+ animation: fade-in 1s ease-in-out 3s forwards;
118
+ }
119
+
120
+ .my-footer img {
121
+ width: 40px; /* Increased the logo size to large */
122
+ height: 40px;
123
+ }
124
+
125
+ @keyframes fade-in {
126
+ 0% {
127
+ bottom: -50px;
128
+ opacity: 0;
129
+ }
130
+ 100% {
131
+ bottom: 0;
132
+ opacity: 1;
133
+ }
134
+ }
135
+ </style>
136
+ <div class='my-footer'>Made by The Raj | Follow me on <a href='https://instagram.com/theraj7171' target='_blank'><img src='https://static.vecteezy.com/system/resources/previews/018/930/692/original/instagram-logo-instagram-icon-transparent-free-png.png' alt='Instagram' width='40' height='40'></a> | Connect with me on <a href='https://www.linkedin.com/in/the-raj71' target='_blank'><img src='https://static.vecteezy.com/system/resources/previews/022/511/448/non_2x/linkedin-logo-editorial-free-vector.jpg' alt='LinkedIn' width='40' height='40'></a> | Check out my <a href='https://github.com/TheRaj71' target='_blank'><img src='https://2.bp.blogspot.com/-7M-f2FzhZl8/WxLdqW_NTMI/AAAAAAAANVw/a5zQzCdh4-89d1OXrPrEYhyarOAFsLY6gCLcBGAs/s640/github-mark.png' alt='GitHub' width='40' height='40'></a></div>
137
+ """
138
+ st.markdown(footer, unsafe_allow_html=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ groq
2
+ streamlit
3
+ python-dotenv