File size: 1,630 Bytes
7ad8e44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
import os
import streamlit as st
from groq import Groq
from dotenv import load_dotenv

# Load environment variables
load_dotenv()
api_key = os.getenv("GROQ_API_KEY")

# Ensure API key is available
if not api_key:
    st.error("API key not found. Please set GROQ_API_KEY in the .env file.")
    st.stop()

# Initialize Groq client
client = Groq(api_key=api_key)

# Function to get chatbot response
def get_chat_response(query):
    chat_completion = client.chat.completions.create(
        messages=[{"role": "user", "content": query}],
        model="llama-3.3-70b-versatile",
    )
    return chat_completion.choices[0].message.content

# Streamlit app interface
def main():
    st.title("Engineering Assistant Chatbot")
    st.write("Ask any engineering-related questions, and I will provide solutions.")

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

    if user_input:
        engineering_keywords = [
            "mechanical", "electrical", "civil", "software", "chemical", "structural", 
            "thermodynamics", "fluid mechanics", "circuit", "power", "robotics", "AI", 
            "automation", "material science", "manufacturing", "electronics", "coding", 
            "design", "engineering problem", "mathematics", "physics", "statics", "dynamics"
        ]
        
        if any(keyword in user_input.lower() for keyword in engineering_keywords):
            response = get_chat_response(user_input)
            st.write("Chatbot Response:", response)
        else:
            st.write("Sorry, I only answer engineering-related questions.")

if __name__ == "__main__":
    main()