Spaces:
Runtime error

FutureYou / app.py
AkanshaRajput's picture
Update app.py
7f83ae0 verified
Raw History Blame Contribute Delete
1.73 kB
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()