Tanseer45203's picture
Create app.py
7ad8e44 verified
Raw
History Blame Contribute Delete
1.63 kB
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()