File size: 1,122 Bytes
8c486b2
cac4f75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c486b2
 
 
 
cac4f75
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
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

# Load model and tokenizer from Hugging Face Hub
model_name = "mjpsm/Positive-Affirmations-Model"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

# Generation function
def generate_affirmation(prompt):
    inputs = tokenizer(prompt, return_tensors="pt")
    with torch.no_grad():
        outputs = model.generate(
            inputs["input_ids"],
            max_new_tokens=100,
            temperature=0.7,
            top_k=50,
            top_p=0.95,
            do_sample=True
        )
    return tokenizer.decode(outputs[0], skip_special_tokens=True)

# Gradio interface
demo = gr.Interface(
    fn=generate_affirmation,
    inputs=gr.Textbox(label="Describe the player situation (e.g., 'struggled with algebra')"),
    outputs=gr.Textbox(label="AI Affirmation"),
    title="Positive Affirmation Generator",
    description="Describe a learning moment, and the model will generate a motivating affirmation."
)

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