File size: 1,175 Bytes
141fef7
 
 
8506e21
 
 
 
 
 
 
141fef7
def9724
 
 
8506e21
 
def9724
8506e21
141fef7
 
def9724
141fef7
 
 
 
def9724
 
141fef7
 
8506e21
 
141fef7
 
def9724
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
import gradio as gr
from transformers import pipeline

# Load the Zephyr-7B model
generator = pipeline(
    "text-generation",
    model="HuggingFaceH4/zephyr-7b-alpha",
    device_map="auto",
    torch_dtype="auto"
)

# Updated function with hazards parameter
def generate_iipp(industry, employees, hazards):
    prompt = (
        f"Write a detailed Injury and Illness Prevention Plan (IIPP) for a {industry} workplace "
        f"with {employees} employees. The workplace includes the following hazards: {hazards}."
    )
    result = generator(prompt, max_new_tokens=512, do_sample=True, temperature=0.7, top_p=0.95)
    return result[0]['generated_text']

# Gradio interface with 3 inputs
demo = gr.Interface(
    fn=generate_iipp,
    inputs=[
        gr.Textbox(label="Industry", placeholder="e.g. warehouse"),
        gr.Number(label="Number of Employees"),
        gr.Textbox(label="Hazards", placeholder="e.g. forklifts, toxic chemicals, noise")
    ],
    outputs="text",
    title="AI-Powered IIPP Generator (Zephyr-7B)",
    description="Enter your industry, number of employees, and workplace hazards to generate a custom IIPP using Zephyr-7B"
)

demo.launch()