Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import requests | |
| # App title | |
| st.set_page_config(page_title="MSDS Emergency Chatbot") | |
| st.title("🧯 MSDS Emergency Chatbot") | |
| st.markdown("Ask for emergency safety measures based on chemical hazards.") | |
| # API config | |
| GROQ_API_KEY = st.secrets.get("GROQ_API_KEY") or "your-groq-api-key" | |
| GROQ_MODEL = "llama3-70b-8192" # You may choose another model from Groq if needed | |
| # Function to query Groq API | |
| 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"] | |
| # Streamlit chat UI | |
| 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) | |