CoolFace
Apppublic

danieljstuart/offshore-hazard-ai

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
backend.py34 linesDownload Raw Back to root
1import openai2import streamlit as st3 4# Load OpenAI API Key5OPENAI_API_KEY = "your-api-key-here"  # ⬅️ Replace this with your actual API key6 7openai.api_key = OPENAI_API_KEY8 9def analyze_hazards(job_description):10    """Sends a job description + image context to OpenAI for hazard analysis."""11    response = openai.ChatCompletion.create(12        model="gpt-4o",13        messages=[14            {"role": "system", "content": "You are an expert in offshore safety and hazard recognition. Provide detailed hazard analysis and controls."},15            {"role": "user", "content": f"Analyze this offshore job and list all hazards and safety controls: {job_description}"}16        ],17        max_tokens=50018    )19    return response["choices"][0]["message"]["content"]20 21# Streamlit UI22st.title("AI Offshore Hazard Detection")23st.write("Enter the job details below to get a hazard analysis.")24 25job_description = st.text_area("Describe the job being performed:")26 27if st.button("Analyze Hazards"):28    if job_description:29        hazard_report = analyze_hazards(job_description)30        st.write("### Hazard Analysis Report:")31        st.write(hazard_report)32    else:33        st.warning("Please enter a job description.")34