adityya7 commited on
Commit
7b1cd48
ยท
verified ยท
1 Parent(s): c96757f

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +59 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,61 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
5
 
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from groq import Groq
3
+ from dotenv import load_dotenv
4
  import streamlit as st
5
 
6
+ # Load environment variables from .env file
7
+ load_dotenv()
8
+
9
+ # Get the API key from environment variable
10
+ api_key = os.getenv("GROQ_API_KEY")
11
+
12
+ # Initialize Groq client with the API key
13
+ client = Groq(api_key=api_key)
14
+
15
+ # Define your chatbot logic for student exam preparation assistant
16
+ def chatbot():
17
+ st.title("Student Exam Preparation Assistant ๐ŸŽ“")
18
+ st.write("Welcome to your personal exam preparation assistant! Whether you're preparing for a high school exam, college exams, or any professional tests, I'm here to help. What would you like assistance with today?")
19
+
20
+ # Add an attractive header with an emoji
21
+ st.markdown("**Ask me anything about exam preparation!**")
22
+ st.markdown("I can help you with study tips, time management strategies, practice questions, and more. Letโ€™s get started! ๐Ÿ˜„")
23
+
24
+ # Input field for the user to type a message
25
+ user_input = st.text_input("Type your exam preparation question here:")
26
+
27
+ # Add a submit button
28
+ if st.button("Submit"):
29
+ if user_input:
30
+ # Display user's input
31
+ st.write(f"You: {user_input}")
32
+
33
+ # Sending user's input to Groq API for completion
34
+ try:
35
+ completion = client.chat.completions.create(
36
+ model="deepseek-r1-distill-llama-70b", # You can change this model based on your preference
37
+ messages=[{"role": "user", "content": user_input}],
38
+ temperature=0.6,
39
+ max_completion_tokens=4096,
40
+ top_p=0.95,
41
+ stream=True,
42
+ stop=None,
43
+ )
44
+
45
+ # Collect the response chunk by chunk
46
+ response = ""
47
+ for chunk in completion:
48
+ # Get the assistant's response from each chunk
49
+ response += chunk.choices[0].delta.content or ""
50
+
51
+ # Display assistant's response
52
+ st.write(f"Assistant: {response}")
53
+
54
+ except Exception as e:
55
+ st.write(f"Error occurred: {e}")
56
+ else:
57
+ st.write("Please type a question before submitting. ๐Ÿ˜Š")
58
+
59
+ # Run the chatbot with dynamic user input
60
+ if __name__ == "__main__":
61
+ chatbot()