| import os |
| import streamlit as st |
| from groq import Groq |
| from dotenv import load_dotenv |
|
|
| |
| load_dotenv() |
| api_key = os.getenv("GROQ_API_KEY") |
|
|
| |
| if not api_key: |
| st.error("API key not found. Please set GROQ_API_KEY in the .env file.") |
| st.stop() |
|
|
| |
| client = Groq(api_key=api_key) |
|
|
| |
| 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 |
|
|
| |
| 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() |
|
|