Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,19 @@
|
|
| 1 |
-
import
|
|
|
|
| 2 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
|
|
|
| 4 |
pipe = pipeline("text-generation", model="google/gemma-2b-it")
|
| 5 |
|
|
|
|
| 6 |
def generate(prompt):
|
| 7 |
-
|
| 8 |
-
return
|
| 9 |
|
|
|
|
| 10 |
iface = gr.Interface(fn=generate, inputs="text", outputs="text")
|
| 11 |
iface.launch()
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from huggingface_hub import login
|
| 3 |
from transformers import pipeline
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
# 🔐 Login using the secret token (set in Space Settings > Secrets)
|
| 7 |
+
login(os.getenv("HF_TOKEN"))
|
| 8 |
|
| 9 |
+
# 🚀 Load the gated model
|
| 10 |
pipe = pipeline("text-generation", model="google/gemma-2b-it")
|
| 11 |
|
| 12 |
+
# 🧠 Generation function
|
| 13 |
def generate(prompt):
|
| 14 |
+
output = pipe(prompt, max_new_tokens=100)
|
| 15 |
+
return output[0]["generated_text"]
|
| 16 |
|
| 17 |
+
# 🎛️ Gradio Interface
|
| 18 |
iface = gr.Interface(fn=generate, inputs="text", outputs="text")
|
| 19 |
iface.launch()
|