| import os | |
| from huggingface_hub import login | |
| from transformers import pipeline | |
| import gradio as gr | |
| # π Login using the secret token (set in Space Settings > Secrets) | |
| login(os.getenv("HF_TOKEN")) | |
| # π Load the gated model | |
| pipe = pipeline("text-generation", model="google/gemma-2b-it") | |
| # π§ Generation function | |
| def generate(prompt): | |
| output = pipe(prompt, max_new_tokens=100) | |
| return output[0]["generated_text"] | |
| # ποΈ Gradio Interface | |
| iface = gr.Interface(fn=generate, inputs="text", outputs="text") | |
| iface.launch() |