Spaces:
Sleeping
Sleeping
| 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("") | |
| # 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) | |