File size: 1,914 Bytes
e94537b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import gradio as gr
import datetime
import openai
import os

openai.api_key = os.getenv("OPENAI_API_KEY")

def generate_story(age, reading_age, gender_pronouns, situation, additional_notes):
    today = datetime.date.today().strftime("%d %B %Y")
    prompt = f"""
Create a social story suitable for a student aged {age} with a reading age of {reading_age}.
Use British English and age-appropriate vocabulary.
Refer to the student using '{gender_pronouns}'.
The story is to help prepare the student for: {situation}.
Use reassuring, inclusive language and structure the story clearly.
{additional_notes if additional_notes else ""}
Use placeholder [student name] wherever a name would normally appear.
    """

    try:
        response = openai.ChatCompletion.create(
            model="gpt-4",
            messages=[
                {"role": "system", "content": "You are a teacher writing simple, clear, and supportive social stories for children with SEND."},
                {"role": "user", "content": prompt}
            ],
            temperature=0.7
        )
        story = response['choices'][0]['message']['content']
        return f"**Date:** {today}\n\n{story}"
    except Exception as e:
        return f"Error generating story: {e}"

interface = gr.Interface(
    fn=generate_story,
    inputs=[
        gr.Number(label="Student's Age", value=10),
        gr.Number(label="Reading Age", value=8),
        gr.Radio(["he/him", "she/her", "they/them"], label="Pronouns"),
        gr.Textbox(lines=2, label="What is the situation you're preparing them for?"),
        gr.Textbox(lines=2, label="Any extra information (optional)")
    ],
    outputs="markdown",
    title="Tower Hamlets Social Story Generator",
    description="This tool creates age-appropriate social stories in British English to support children with SEND. Names are anonymised."
)

if __name__ == "__main__":
    interface.launch()