Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
model_name = "ayyuce/SmolGRPO-135M"
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 9 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 10 |
+
model.to("cpu")
|
| 11 |
+
|
| 12 |
+
def generate_text(prompt):
|
| 13 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 14 |
+
inputs = {key: value.to("cpu") for key, value in inputs.items()}
|
| 15 |
+
outputs = model.generate(**inputs, max_length=100, do_sample=True, top_p=0.95, top_k=50)
|
| 16 |
+
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 17 |
+
return generated_text
|
| 18 |
+
|
| 19 |
+
demo = gr.Interface(
|
| 20 |
+
fn=generate_text,
|
| 21 |
+
inputs="text",
|
| 22 |
+
outputs="text",
|
| 23 |
+
title="SmolGRPO-135M Generator",
|
| 24 |
+
description="Generate text with the SmolGRPO-135M."
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
if __name__ == "__main__":
|
| 28 |
+
demo.launch()
|