Spaces:
Sleeping
Sleeping
Download app.py from Reddwalkermedia/IIPP-generator: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/spaces/Reddwalkermedia/IIPP-generator/resolve/main/app.py
- Command line
-
hf download hf://spaces/Reddwalkermedia/IIPP-generator/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Reddwalkermedia/IIPP-generator/resolve/main/app.py
1.18 kB
| 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() | |