File size: 1,872 Bytes
72d0fa2
 
a02992e
72d0fa2
a02992e
 
72d0fa2
a02992e
 
 
 
 
 
 
 
 
 
 
72d0fa2
a02992e
72d0fa2
a02992e
72d0fa2
 
 
 
 
 
 
 
 
a02992e
 
 
 
 
72d0fa2
 
 
 
 
 
 
 
a02992e
c9c528e
72d0fa2
c9c528e
 
72d0fa2
c9c528e
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
50
51
52
import streamlit as st
import requests
import os

# App config
st.set_page_config(page_title="Chemical Emergency Chatbot", page_icon="☣️")

# Try to load image
if os.path.exists("1000087676.jpg"):
    st.image("1000087676.jpg", width=200)
else:
    st.markdown("![Default Image](https://upload.wikimedia.org/wikipedia/commons/thumb/6/63/Hazard_C.svg/1200px-Hazard_C.svg.png)")

# Title and subtitle
st.title("☣️ CHEMICAL EMERGENCY CHATBOT")
st.markdown("Get rapid guidance for handling hazardous chemical incidents, spills, or toxic releases.")

# API Config
GROQ_API_KEY = st.secrets.get("GROQ_API_KEY") or "your-groq-api-key"
GROQ_MODEL = "llama3-70b-8192"

# Groq API Query Function
def query_groq(prompt):
    url = "https://api.groq.com/openai/v1/chat/completions"
    headers = {
        "Authorization": f"Bearer {GROQ_API_KEY}",
        "Content-Type": "application/json"
    }
    payload = {
        "model": GROQ_MODEL,
        "messages": [
            {"role": "system", "content": (
                "You are an emergency safety response assistant. Based on MSDS information, "
                "give specific, clear, and concise guidance in emergency situations involving "
                "hazardous chemical spills, toxic gas releases, or fires involving flammable substances."
            )},
            {"role": "user", "content": prompt}
        ],
        "temperature": 0.2
    }
    response = requests.post(url, headers=headers, json=payload)
    response.raise_for_status()
    return response.json()["choices"][0]["message"]["content"]

# Chat input
user_input = st.chat_input("Enter your chemical emergency question here...")
if user_input:
    st.chat_message("user").write(user_input)
    with st.spinner("Getting emergency response information..."):
        reply = query_groq(user_input)
    st.chat_message("assistant").write(reply)