Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,87 +1,4 @@
|
|
1 |
-
import os
|
2 |
import streamlit as st
|
3 |
-
from groq import Groq
|
4 |
-
|
5 |
-
# Set the Groq API key
|
6 |
-
os.environ["GROQ_API_KEY"] = "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"
|
7 |
-
|
8 |
-
# Initialize Groq client
|
9 |
-
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
|
10 |
-
|
11 |
-
# Define the LLaMA model to be used
|
12 |
-
MODEL_NAME = "llama3-8b-8192"
|
13 |
-
|
14 |
-
# Function to call Groq API
|
15 |
-
def call_groq_api(prompt):
|
16 |
-
try:
|
17 |
-
chat_completion = client.chat.completions.create(
|
18 |
-
messages=[{"role": "user", "content": prompt}],
|
19 |
-
model=MODEL_NAME
|
20 |
-
)
|
21 |
-
return chat_completion.choices[0].message.content
|
22 |
-
except Exception as e:
|
23 |
-
return f"Error: {str(e)}"
|
24 |
-
|
25 |
-
# Define functions for each tool
|
26 |
-
def personalized_learning_assistant(topic):
|
27 |
-
examples = [
|
28 |
-
"Explain quantum mechanics with a real-world example.",
|
29 |
-
"Describe general relativity and its significance.",
|
30 |
-
"Provide a simple explanation of machine learning and its applications."
|
31 |
-
]
|
32 |
-
prompt = f"Here are some example explanations:\n\n{examples}\n\nNow, explain the topic: {topic}. Provide a detailed, yet simple explanation with a practical example."
|
33 |
-
return call_groq_api(prompt)
|
34 |
-
|
35 |
-
def ai_coding_mentor(code_snippet):
|
36 |
-
examples = [
|
37 |
-
"Review this code snippet for optimization opportunities:\n\nCode: 'for i in range(10): print(i)'\nSuggestion: Use list comprehension for more efficient code.",
|
38 |
-
"Analyze this code snippet for best practices:\n\nCode: 'def add(a, b): return a + b'\nSuggestion: Include type hints to improve readability and maintainability."
|
39 |
-
]
|
40 |
-
prompt = f"Here are some code review examples:\n\n{examples}\n\nReview the following code snippet and provide suggestions for improvement:\n{code_snippet}. Include any potential issues or improvements."
|
41 |
-
return call_groq_api(prompt)
|
42 |
-
|
43 |
-
def smart_document_summarizer(document_text):
|
44 |
-
examples = [
|
45 |
-
"Summarize this text:\n\nText: 'Quantum computing represents a revolutionary approach to computing that leverages quantum mechanics.'\nSummary: 'Quantum computing uses quantum mechanics to advance computing technology.'",
|
46 |
-
"Create a summary for this passage:\n\nText: 'The rise of electric vehicles is a major step towards reducing global carbon emissions and combating climate change.'\nSummary: 'Electric vehicles help reduce carbon emissions and fight climate change.'"
|
47 |
-
]
|
48 |
-
prompt = f"Here are some document summarization examples:\n\n{examples}\n\nSummarize the following document text concisely:\n{document_text}. Focus on capturing the main points clearly."
|
49 |
-
return call_groq_api(prompt)
|
50 |
-
|
51 |
-
def interactive_study_planner(exam_schedule):
|
52 |
-
examples = [
|
53 |
-
"Generate a study plan for a schedule with multiple exams in a week:\n\nSchedule: '3 exams in one week'\nPlan: 'Allocate 2 hours per subject each day, with review sessions on weekends.'",
|
54 |
-
"Create a study plan for preparing for exams over a period of 2 weeks:\n\nSchedule: 'Exams in 2 weeks'\nPlan: 'Prioritize subjects based on difficulty and importance, with daily reviews and mock tests.'"
|
55 |
-
]
|
56 |
-
prompt = f"Here are some study planning examples:\n\n{examples}\n\nCreate a tailored study plan based on the following schedule:\n{exam_schedule}. Include daily study goals and break times."
|
57 |
-
return call_groq_api(prompt)
|
58 |
-
|
59 |
-
def real_time_qa_support(question):
|
60 |
-
examples = [
|
61 |
-
"Provide an answer to this question:\n\nQuestion: 'What is Newton's third law of motion?'\nAnswer: 'Newton's third law states that for every action, there is an equal and opposite reaction.'",
|
62 |
-
"Explain this concept:\n\nQuestion: 'What is the principle of conservation of energy?'\nAnswer: 'The principle of conservation of energy states that energy cannot be created or destroyed, only transformed from one form to another.'"
|
63 |
-
]
|
64 |
-
prompt = f"Here are some examples of answers to academic questions:\n\n{examples}\n\nAnswer the following question:\n{question}. Provide a clear and comprehensive explanation."
|
65 |
-
return call_groq_api(prompt)
|
66 |
-
|
67 |
-
def mental_health_check_in(feelings):
|
68 |
-
examples = [
|
69 |
-
"Offer advice for managing exam stress:\n\nFeeling: 'Stressed about upcoming exams'\nAdvice: 'Develop a study schedule, take regular breaks, and practice relaxation techniques.'",
|
70 |
-
"Provide support for feeling overwhelmed:\n\nFeeling: 'Feeling overwhelmed with coursework'\nAdvice: 'Break tasks into smaller, manageable parts and seek support from peers or a counselor.'"
|
71 |
-
]
|
72 |
-
prompt = f"Here are some examples of mental health advice:\n\n{examples}\n\nProvide advice based on the following feeling:\n{feelings}. Offer practical suggestions for improving well-being."
|
73 |
-
return call_groq_api(prompt)
|
74 |
-
|
75 |
-
# Initialize session state if not already set
|
76 |
-
if 'responses' not in st.session_state:
|
77 |
-
st.session_state['responses'] = {
|
78 |
-
"personalized_learning_assistant": "",
|
79 |
-
"ai_coding_mentor": "",
|
80 |
-
"smart_document_summarizer": "",
|
81 |
-
"interactive_study_planner": "",
|
82 |
-
"real_time_qa_support": "",
|
83 |
-
"mental_health_check_in": ""
|
84 |
-
}
|
85 |
|
86 |
# Define Streamlit app
|
87 |
st.set_page_config(page_title="EduNexus", page_icon=":book:", layout="wide")
|
@@ -121,6 +38,25 @@ st.markdown("""
|
|
121 |
.stSidebar .stMarkdown {
|
122 |
color: #ffffff;
|
123 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
</style>
|
125 |
""", unsafe_allow_html=True)
|
126 |
|
@@ -233,9 +169,10 @@ elif selected_tool == "Mental Health Check-In":
|
|
233 |
|
234 |
# Footer with acknowledgments
|
235 |
st.markdown("""
|
236 |
-
<
|
237 |
-
<p
|
238 |
-
<
|
239 |
-
<
|
240 |
-
|
|
|
241 |
""", unsafe_allow_html=True)
|
|
|
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
# Define Streamlit app
|
4 |
st.set_page_config(page_title="EduNexus", page_icon=":book:", layout="wide")
|
|
|
38 |
.stSidebar .stMarkdown {
|
39 |
color: #ffffff;
|
40 |
}
|
41 |
+
.footer {
|
42 |
+
background-color: #1e1e2f;
|
43 |
+
padding: 10px;
|
44 |
+
text-align: center;
|
45 |
+
color: #ffffff;
|
46 |
+
border-top: 1px solid #ff9a8b;
|
47 |
+
}
|
48 |
+
.footer a {
|
49 |
+
color: #ff9a8b;
|
50 |
+
margin: 0 10px;
|
51 |
+
text-decoration: none;
|
52 |
+
font-size: 18px;
|
53 |
+
}
|
54 |
+
.footer a:hover {
|
55 |
+
color: #ffffff;
|
56 |
+
}
|
57 |
+
.footer i {
|
58 |
+
font-size: 20px;
|
59 |
+
}
|
60 |
</style>
|
61 |
""", unsafe_allow_html=True)
|
62 |
|
|
|
169 |
|
170 |
# Footer with acknowledgments
|
171 |
st.markdown("""
|
172 |
+
<div class="footer">
|
173 |
+
<p>Developed by MUHAMMD IBRAHIM ❤ </p>
|
174 |
+
<a href="https://github.com/muhammadibrahim313"><i class="fab fa-github"></i></a>
|
175 |
+
<a href="https://www.kaggle.com/muhammadibrahimqasmi"><i class="fab fa-kaggle"></i></a>
|
176 |
+
<a href="https://www.linkedin.com/in/muhammad-ibrahim-qasmi-9876a1297/"><i class="fab fa-linkedin"></i></a>
|
177 |
+
</div>
|
178 |
""", unsafe_allow_html=True)
|