mjpsm's picture
Create app.py
3fd1602 verified
import gradio as gr
from transformers import pipeline
# Load your fine-tuned model from Hugging Face Hub
model_name = "mjpsm/math-affirmation-model"
generator = pipeline("text2text-generation", model=model_name)
# Define the interface function
def generate_affirmation(situation):
result = generator(situation, max_length=64, clean_up_tokenization_spaces=True)[0]["generated_text"]
return result
# Gradio UI
title = "πŸŽ“ Math Affirmation Generator"
description = """
Enter a student's situation, struggle, or emotional state during a math activity.
This model, trained on Math Narrative-aligned affirmations, will respond with a positive and empathetic affirmation.
Example prompts:
- "Felt overwhelmed after missing several questions"
- "Struggled with algebra problems"
- "Lost confidence after being wrong in front of peers"
"""
demo = gr.Interface(
fn=generate_affirmation,
inputs=gr.Textbox(lines=3, placeholder="Enter the student's situation here..."),
outputs=gr.Textbox(label="Affirmation"),
title=title,
description=description,
theme="soft"
)
demo.launch()