Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,17 +11,17 @@ def generate(
|
|
| 11 |
temperature=0.4,
|
| 12 |
top_p=0.95,
|
| 13 |
top_k=50,
|
| 14 |
-
max_new_tokens=
|
| 15 |
):
|
| 16 |
pipe = load_model(model_name)
|
| 17 |
-
#
|
| 18 |
if template_name == "Falcon 1B Template":
|
| 19 |
message_template = [
|
| 20 |
{"role": "user", "content": "Hello!"},
|
| 21 |
{"role": "assistant", "content": "Hello! How can I assist you today?"},
|
| 22 |
{"role": "user", "content": user_input},
|
| 23 |
]
|
| 24 |
-
else: #
|
| 25 |
message_template = [
|
| 26 |
{
|
| 27 |
"role": "system",
|
|
@@ -30,7 +30,6 @@ def generate(
|
|
| 30 |
{"role": "user", "content": user_input},
|
| 31 |
]
|
| 32 |
|
| 33 |
-
# Set tokenize correctly. Otherwise ticking the box breaks it.
|
| 34 |
prompt = pipe.tokenizer.apply_chat_template(message_template, tokenize=False, add_generation_prompt=True)
|
| 35 |
outputs = pipe(prompt, max_new_tokens=max_new_tokens, do_sample=True,
|
| 36 |
temperature=temperature, top_k=top_k, top_p=top_p, repetition_penalty=1.10)
|
|
@@ -38,7 +37,7 @@ def generate(
|
|
| 38 |
|
| 39 |
model_choices = ["TinyLlama/TinyLlama-1.1B-Chat-v1.0", "ericzzz/falcon-rw-1b-chat"]
|
| 40 |
template_choices = ["TinyLlama Template", "Falcon Template"]
|
| 41 |
-
|
| 42 |
g = gr.Interface(
|
| 43 |
fn=generate,
|
| 44 |
inputs=[
|
|
@@ -48,12 +47,13 @@ g = gr.Interface(
|
|
| 48 |
gr.components.Slider(minimum=0, maximum=1, value=0.4, label="Temperature"),
|
| 49 |
gr.components.Slider(minimum=0, maximum=1, value=0.95, label="Top p"),
|
| 50 |
gr.components.Slider(minimum=0, maximum=100, step=1, value=50, label="Top k"),
|
| 51 |
-
gr.components.Slider(minimum=1, maximum=1024, step=1, value=
|
| 52 |
],
|
| 53 |
outputs=[gr.Textbox(lines=10, label="Output")],
|
| 54 |
title="Hugging Face Transformers Model",
|
| 55 |
description="A simple interface for generating text with a Hugging Face Transformers model.",
|
|
|
|
| 56 |
concurrency_limit=1
|
| 57 |
)
|
| 58 |
|
| 59 |
-
g.launch(max_threads=2)
|
|
|
|
| 11 |
temperature=0.4,
|
| 12 |
top_p=0.95,
|
| 13 |
top_k=50,
|
| 14 |
+
max_new_tokens=256,
|
| 15 |
):
|
| 16 |
pipe = load_model(model_name)
|
| 17 |
+
# Hier weitere Optionen hinzufügen
|
| 18 |
if template_name == "Falcon 1B Template":
|
| 19 |
message_template = [
|
| 20 |
{"role": "user", "content": "Hello!"},
|
| 21 |
{"role": "assistant", "content": "Hello! How can I assist you today?"},
|
| 22 |
{"role": "user", "content": user_input},
|
| 23 |
]
|
| 24 |
+
else: # Standardmäßig "TinyLlama Template"
|
| 25 |
message_template = [
|
| 26 |
{
|
| 27 |
"role": "system",
|
|
|
|
| 30 |
{"role": "user", "content": user_input},
|
| 31 |
]
|
| 32 |
|
|
|
|
| 33 |
prompt = pipe.tokenizer.apply_chat_template(message_template, tokenize=False, add_generation_prompt=True)
|
| 34 |
outputs = pipe(prompt, max_new_tokens=max_new_tokens, do_sample=True,
|
| 35 |
temperature=temperature, top_k=top_k, top_p=top_p, repetition_penalty=1.10)
|
|
|
|
| 37 |
|
| 38 |
model_choices = ["TinyLlama/TinyLlama-1.1B-Chat-v1.0", "ericzzz/falcon-rw-1b-chat"]
|
| 39 |
template_choices = ["TinyLlama Template", "Falcon Template"]
|
| 40 |
+
|
| 41 |
g = gr.Interface(
|
| 42 |
fn=generate,
|
| 43 |
inputs=[
|
|
|
|
| 47 |
gr.components.Slider(minimum=0, maximum=1, value=0.4, label="Temperature"),
|
| 48 |
gr.components.Slider(minimum=0, maximum=1, value=0.95, label="Top p"),
|
| 49 |
gr.components.Slider(minimum=0, maximum=100, step=1, value=50, label="Top k"),
|
| 50 |
+
gr.components.Slider(minimum=1, maximum=1024, step=1, value=256, label="Max tokens"),
|
| 51 |
],
|
| 52 |
outputs=[gr.Textbox(lines=10, label="Output")],
|
| 53 |
title="Hugging Face Transformers Model",
|
| 54 |
description="A simple interface for generating text with a Hugging Face Transformers model.",
|
| 55 |
+
theme='syddharth/gray-minimal', # Hinzugefügtes Theme
|
| 56 |
concurrency_limit=1
|
| 57 |
)
|
| 58 |
|
| 59 |
+
g.launch(max_threads=2)
|