Spaces:
Sleeping
Sleeping
Limitation update0
Browse files
app.py
CHANGED
|
@@ -1,6 +1,11 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
from huggingface_hub import InferenceClient
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def respond(
|
| 6 |
message,
|
|
@@ -21,23 +26,49 @@ def respond(
|
|
| 21 |
|
| 22 |
return output
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
demo = gr.Interface(
|
| 26 |
fn=respond,
|
| 27 |
title="Text Generation Playground",
|
| 28 |
description="Model: meta-llama/Llama-3.1-8B",
|
| 29 |
inputs=[
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
#
|
| 36 |
-
#
|
| 37 |
-
# Query:
|
| 38 |
-
# Answer:
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
gr.Slider(minimum=0, maximum=2.0, value=1, step=0.01, label="Temperature"),
|
| 42 |
gr.Slider(
|
| 43 |
minimum=0.1,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
+
import tiktoken
|
| 5 |
+
|
| 6 |
+
def count_tokens(text):
|
| 7 |
+
enc = tiktoken.get_encoding("cl100k_base")
|
| 8 |
+
return len(enc.encode(text))
|
| 9 |
|
| 10 |
def respond(
|
| 11 |
message,
|
|
|
|
| 26 |
|
| 27 |
return output
|
| 28 |
|
| 29 |
+
token_counter = gr.Number(label="Token Count", value=0, interactive=False)
|
| 30 |
+
|
| 31 |
+
input_box = gr.Textbox(
|
| 32 |
+
lines=15,
|
| 33 |
+
label="Input Prompt",
|
| 34 |
+
placeholder="""Copy-Paste your own alignment prompt here:
|
| 35 |
+
E.g. # System-level prompt: You are a helpful assistant...\n
|
| 36 |
+
# Query: Who painted the Mona Lisa?\n
|
| 37 |
+
# Answer: The Mona Lisa was painted by Leonardo da Vinci, an Italian Renaissance artist, between 1503 and 1506, though some believe he may have continued working on it until 1517. It is one of the most famous and iconic works of art in history, known for its enigmatic expression and masterful technique.\n
|
| 38 |
+
# Query: ...\n
|
| 39 |
+
# Answer:
|
| 40 |
+
|
| 41 |
+
**Due to the limitations of the service, keep your prompt under 256 tokens.**"""
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
def update_token_count(text):
|
| 45 |
+
token_len = count_tokens(text)
|
| 46 |
+
if token_len > 256:
|
| 47 |
+
text = text[:len(text)//2] # simple truncation fallback
|
| 48 |
+
return token_len
|
| 49 |
+
|
| 50 |
+
input_box.change(fn=update_token_count, inputs=input_box, outputs=token_counter)
|
| 51 |
|
| 52 |
demo = gr.Interface(
|
| 53 |
fn=respond,
|
| 54 |
title="Text Generation Playground",
|
| 55 |
description="Model: meta-llama/Llama-3.1-8B",
|
| 56 |
inputs=[
|
| 57 |
+
input_box,
|
| 58 |
+
token_counter,
|
| 59 |
+
# gr.Textbox(
|
| 60 |
+
# lines=15,
|
| 61 |
+
# label="Input Prompt",
|
| 62 |
+
# placeholder="""Copy-Paste your own alignment prompt here:
|
| 63 |
+
# E.g. # System-level prompt: You are a helpful assistant...\n
|
| 64 |
+
# # Query: Who painted the Mona Lisa?\n
|
| 65 |
+
# # Answer: The Mona Lisa was painted by Leonardo da Vinci, an Italian Renaissance artist, between 1503 and 1506, though some believe he may have continued working on it until 1517. It is one of the most famous and iconic works of art in history, known for its enigmatic expression and masterful technique.\n
|
| 66 |
+
# # Query: ...\n
|
| 67 |
+
# # Answer:
|
| 68 |
+
|
| 69 |
+
# **Due to the limitations of the service, keep your prompt under 256 tokens.**""",
|
| 70 |
+
# ),
|
| 71 |
+
gr.Slider(minimum=1, maximum=256, value=100, step=1, label="Max new tokens"),
|
| 72 |
gr.Slider(minimum=0, maximum=2.0, value=1, step=0.01, label="Temperature"),
|
| 73 |
gr.Slider(
|
| 74 |
minimum=0.1,
|