File size: 1,793 Bytes
397b6e4
 
768c17c
397b6e4
768c17c
 
397b6e4
768c17c
 
397b6e4
768c17c
 
 
c24e7a3
768c17c
c24e7a3
 
 
 
397b6e4
 
 
768c17c
 
 
 
7e6ca88
 
768c17c
7e6ca88
397b6e4
768c17c
397b6e4
0f265e1
768c17c
 
397b6e4
 
768c17c
397b6e4
768c17c
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import streamlit as st
import os
from groq import Groq

# Get Groq API Key from environment variables
GROQ_API_KEY = os.getenv("GROQ_API_KEY")

if not GROQ_API_KEY:
    st.error("API key is missing! Please set GROQ_API_KEY in your environment variables.")
else:
    client = Groq(api_key=GROQ_API_KEY)

    def get_groq_response(user_input):
        """Generate a response using the Groq API with the LLaMA model and strict filtering."""
        system_prompt = (
            "You are an AI assistant that only responds to questions about challenges and solutions "
            "for schools, colleges, and universities in underserved regions. If the query is not related "
            "to this topic, respond with: 'I'm sorry, but I can only assist with education-related challenges in underserved regions.' "
            "Do not answer any other questions."
        )

        try:
            chat_completion = client.chat.completions.create(
                messages=[
                    {"role": "system", "content": system_prompt},
                    {"role": "user", "content": user_input}
                ],
                model="llama3-70b-8192"
            )
            return chat_completion.choices[0].message.content
        except Exception as e:
            return f"Error: {str(e)}"

    # Streamlit UI
    st.title("EduConnect Chatbot (Groq LLaMA-3 70B)")
    st.write("Ask about challenges and solutions for schools, colleges, or universities in underserved regions.")

    user_input = st.text_input("Enter your question:")

    if st.button("Submit"):
        if user_input.strip():
            response = get_groq_response(user_input)
            st.write("### Response:")
            st.write(response)
        else:
            st.warning("Please enter a question.")