File size: 1,381 Bytes
6673d09
b9a10da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6673d09
b9a10da
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)