bk939448 commited on
Commit
2d8fea2
·
verified ·
1 Parent(s): b9e955c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -1,11 +1,19 @@
1
- import gradio as gr
 
2
  from transformers import pipeline
 
 
 
 
3
 
 
4
  pipe = pipeline("text-generation", model="google/gemma-2b-it")
5
 
 
6
  def generate(prompt):
7
- result = pipe(prompt, max_new_tokens=100)
8
- return result[0]["generated_text"]
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()