Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,14 +9,7 @@ MODEL_CHOICES = {
|
|
| 9 |
}
|
| 10 |
|
| 11 |
|
| 12 |
-
def complete_text(
|
| 13 |
-
prompt: str,
|
| 14 |
-
max_tokens: int,
|
| 15 |
-
temperature: float,
|
| 16 |
-
top_p: float,
|
| 17 |
-
model_choice: str,
|
| 18 |
-
hf_token: gr.OAuthToken, # token provided after user logs in
|
| 19 |
-
):
|
| 20 |
"""
|
| 21 |
Generate a text completion from a Hugging Face model, streamed chunk by chunk.
|
| 22 |
"""
|
|
@@ -24,8 +17,7 @@ def complete_text(
|
|
| 24 |
yield "⚠️ Please enter a prompt."
|
| 25 |
return
|
| 26 |
|
| 27 |
-
|
| 28 |
-
if not getattr(hf_token, "token", None):
|
| 29 |
yield "🔐 Please login with your Hugging Face account (see left sidebar)."
|
| 30 |
return
|
| 31 |
|
|
@@ -57,11 +49,7 @@ with gr.Blocks() as demo:
|
|
| 57 |
|
| 58 |
with gr.Row():
|
| 59 |
with gr.Column(scale=2):
|
| 60 |
-
prompt = gr.Textbox(
|
| 61 |
-
label="Prompt",
|
| 62 |
-
placeholder="Type the beginning of your text...",
|
| 63 |
-
lines=4,
|
| 64 |
-
)
|
| 65 |
max_tokens = gr.Slider(1, 1024, value=100, step=1, label="Max new tokens")
|
| 66 |
temperature = gr.Slider(0.0, 2.0, value=0.7, step=0.1, label="Temperature")
|
| 67 |
top_p = gr.Slider(0.1, 1.0, value=1.0, step=0.05, label="Top-p")
|
|
@@ -73,10 +61,10 @@ with gr.Blocks() as demo:
|
|
| 73 |
submit = gr.Button("Generate Completion")
|
| 74 |
with gr.Column(scale=3):
|
| 75 |
with gr.Sidebar():
|
| 76 |
-
login = gr.LoginButton() # supplies OAuth token
|
| 77 |
output = gr.Textbox(label="Generated Completion", lines=15)
|
| 78 |
|
| 79 |
-
#
|
| 80 |
submit.click(
|
| 81 |
fn=complete_text,
|
| 82 |
inputs=[prompt, max_tokens, temperature, top_p, model_choice, login],
|
|
|
|
| 9 |
}
|
| 10 |
|
| 11 |
|
| 12 |
+
def complete_text(prompt, max_tokens, temperature, top_p, model_choice, hf_token):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
"""
|
| 14 |
Generate a text completion from a Hugging Face model, streamed chunk by chunk.
|
| 15 |
"""
|
|
|
|
| 17 |
yield "⚠️ Please enter a prompt."
|
| 18 |
return
|
| 19 |
|
| 20 |
+
if not hf_token or not getattr(hf_token, "token", None):
|
|
|
|
| 21 |
yield "🔐 Please login with your Hugging Face account (see left sidebar)."
|
| 22 |
return
|
| 23 |
|
|
|
|
| 49 |
|
| 50 |
with gr.Row():
|
| 51 |
with gr.Column(scale=2):
|
| 52 |
+
prompt = gr.Textbox(label="Prompt", placeholder="Type the beginning of your text...", lines=4)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
max_tokens = gr.Slider(1, 1024, value=100, step=1, label="Max new tokens")
|
| 54 |
temperature = gr.Slider(0.0, 2.0, value=0.7, step=0.1, label="Temperature")
|
| 55 |
top_p = gr.Slider(0.1, 1.0, value=1.0, step=0.05, label="Top-p")
|
|
|
|
| 61 |
submit = gr.Button("Generate Completion")
|
| 62 |
with gr.Column(scale=3):
|
| 63 |
with gr.Sidebar():
|
| 64 |
+
login = gr.LoginButton() # supplies OAuth token
|
| 65 |
output = gr.Textbox(label="Generated Completion", lines=15)
|
| 66 |
|
| 67 |
+
# Function has 6 args, so inputs list must have exactly 6 items
|
| 68 |
submit.click(
|
| 69 |
fn=complete_text,
|
| 70 |
inputs=[prompt, max_tokens, temperature, top_p, model_choice, login],
|