File size: 1,728 Bytes
11887c6 7f83ae0 11887c6 d49c39d 1b0716b 11887c6 93a8955 1b0716b 93a8955 1b0716b 93a8955 11887c6 | 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 | import openai
import gradio as gr
client = openai.OpenAI(api_key="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")
def generate_letter(learned, challenge, goal, fear):
prompt = f"""
You are the user's future self, writing them a warm, supportive, and motivating letter.
Use their answers below to personalize the letter:
- What I learned this year: {learned}
- My biggest challenge: {challenge}
- What I want to achieve next year: {goal}
- My biggest fear: {fear}
Write in the first person, as if you are their future self talking to them now.
Be gentle, encouraging, and realistic. End with one practical step they can take tomorrow to move forward.
Keep it under 200 words.
"""
try:
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt}
]
)
return response.choices[0].message.content
except Exception as e:
return f"Error: {e}"
iface = gr.Interface(
fn=generate_letter,
inputs=[
gr.Textbox(label="What did you learn this year?"),
gr.Textbox(label="What was your biggest challenge?"),
gr.Textbox(label="What do you want to achieve next year?"),
gr.Textbox(label="What’s your biggest fear or block?")
],
outputs="text",
title="💌 Letter From Your Future Self",
description="Fill in your reflections and get a short letter from your future self. Take a moment to connect with your dreams ✨"
)
iface.launch() |