Engr-arehmankhan786's picture
Update app.py
ae65ea7 verified
import streamlit as st
from groq import Groq
from PIL import Image
# --- Streamlit Page Configuration ---
st.set_page_config(page_title="CheM Energy ChatBot", layout="centered")
# --- Load API Key from Hugging Face Secrets ---
GROQ_API_KEY = st.secrets["Groq_API_Key"]
# --- Optional: Display Logo/Image if available ---
try:
image = Image.open("1000087676.jpg") # Replace with your image filename
st.image(image, use_column_width=True)
except FileNotFoundError:
st.warning("⚠️ Image not found. You can upload '1000087676.jpg' to display it.")
# --- App Title ---
st.title("🧪 CheM Energy ChatBot")
st.markdown("Ask me anything about **Chemical** or **Energy Engineering**.")
# --- Text Input from User ---
user_input = st.text_input("Enter your question:")
# --- Process User Input ---
if user_input:
with st.spinner("Thinking..."):
client = Groq(api_key=GROQ_API_KEY)
response = client.chat.completions.create(
model="llama3-8b-8192",
messages=[
{"role": "system", "content": "You are a helpful assistant specialized in Chemical and Energy Engineering."},
{"role": "user", "content": user_input}
]
)
# Extract and display response
bot_reply = response.choices[0].message.content
st.success("✅ Answer:")
st.write(bot_reply)