Spaces:
Running
on
Zero
Running
on
Zero
attempt9 fix
Browse files
app.py
CHANGED
@@ -1,7 +1,5 @@
|
|
1 |
-
import
|
2 |
-
from threading import Thread
|
3 |
from typing import Iterator
|
4 |
-
|
5 |
import gradio as gr
|
6 |
import spaces
|
7 |
import torch
|
@@ -11,33 +9,27 @@ MAX_MAX_NEW_TOKENS = 2048
|
|
11 |
DEFAULT_MAX_NEW_TOKENS = 1024
|
12 |
MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
|
13 |
|
|
|
|
|
|
|
|
|
|
|
14 |
DESCRIPTION = """\
|
15 |
-
#
|
16 |
-
This Space demonstrates model [Nekochu/Luminia-13B-v3](https://huggingface.co/Nekochu/Luminia-13B-v3) by Nekochu, a Llama 2 model with 13B parameters fine-tuned for SD gen prompt
|
17 |
-
"""
|
18 |
|
19 |
-
|
20 |
-
<p/>
|
21 |
-
---.
|
22 |
"""
|
23 |
|
24 |
-
|
25 |
-
DESCRIPTION += "\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>"
|
26 |
-
|
27 |
-
|
28 |
-
if torch.cuda.is_available():
|
29 |
-
model_id = "Nekochu/Luminia-13B-v3"
|
30 |
-
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", load_in_4bit=True)
|
31 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
32 |
-
tokenizer.use_default_system_prompt = False
|
33 |
|
|
|
|
|
34 |
|
35 |
-
@spaces.GPU(duration=120)
|
36 |
def generate(
|
37 |
-
model_id: str,
|
38 |
message: str,
|
39 |
chat_history: list[tuple[str, str]],
|
40 |
system_prompt: str,
|
|
|
41 |
max_new_tokens: int = 1024,
|
42 |
temperature: float = 0.6,
|
43 |
top_p: float = 0.9,
|
@@ -80,11 +72,11 @@ def generate(
|
|
80 |
outputs.append(text)
|
81 |
yield "".join(outputs)
|
82 |
|
83 |
-
|
84 |
chat_interface = gr.ChatInterface(
|
85 |
fn=generate,
|
86 |
additional_inputs=[
|
87 |
-
|
88 |
gr.Textbox(label="System prompt", lines=6),
|
89 |
gr.Slider(
|
90 |
label="Max new tokens",
|
@@ -123,10 +115,9 @@ chat_interface = gr.ChatInterface(
|
|
123 |
),
|
124 |
],
|
125 |
stop_btn=None,
|
126 |
-
outputs="text",
|
127 |
examples=[
|
128 |
-
["
|
129 |
-
["
|
130 |
],
|
131 |
)
|
132 |
|
@@ -137,4 +128,4 @@ with gr.Blocks(css="style.css") as demo:
|
|
137 |
gr.Markdown(LICENSE)
|
138 |
|
139 |
if __name__ == "__main__":
|
140 |
-
demo.queue(max_size=20).launch()
|
|
|
1 |
+
rom threading import Thread
|
|
|
2 |
from typing import Iterator
|
|
|
3 |
import gradio as gr
|
4 |
import spaces
|
5 |
import torch
|
|
|
9 |
DEFAULT_MAX_NEW_TOKENS = 1024
|
10 |
MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
|
11 |
|
12 |
+
MODELS = {
|
13 |
+
"Nekochu/Luminia-13B-v3": "Default - Nekochu/Luminia-13B-v3",
|
14 |
+
"Nekochu/Llama-2-13B-German-ORPO": "German ORPO - Nekochu/Llama-2-13B-German-ORPO",
|
15 |
+
}
|
16 |
+
|
17 |
DESCRIPTION = """\
|
18 |
+
# Text Generation with Selectable Models
|
|
|
|
|
19 |
|
20 |
+
This Space demonstrates text generation using different models. Choose a model from the dropdown and experience its creative capabilities!
|
|
|
|
|
21 |
"""
|
22 |
|
23 |
+
LICENSE = """<p/> ---."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
+
if not torch.cuda.is_available():
|
26 |
+
DESCRIPTION += "\n<p>Running on CPU This demo does not work on CPU.</p>"
|
27 |
|
|
|
28 |
def generate(
|
|
|
29 |
message: str,
|
30 |
chat_history: list[tuple[str, str]],
|
31 |
system_prompt: str,
|
32 |
+
model_id: str,
|
33 |
max_new_tokens: int = 1024,
|
34 |
temperature: float = 0.6,
|
35 |
top_p: float = 0.9,
|
|
|
72 |
outputs.append(text)
|
73 |
yield "".join(outputs)
|
74 |
|
75 |
+
model_dropdown = gr.Dropdown(label="Select Model", choices=list(MODELS.values()))
|
76 |
chat_interface = gr.ChatInterface(
|
77 |
fn=generate,
|
78 |
additional_inputs=[
|
79 |
+
model_dropdown,
|
80 |
gr.Textbox(label="System prompt", lines=6),
|
81 |
gr.Slider(
|
82 |
label="Max new tokens",
|
|
|
115 |
),
|
116 |
],
|
117 |
stop_btn=None,
|
|
|
118 |
examples=[
|
119 |
+
["### Instruction: Create stable diffusion metadata based on the given english description. Luminia ### Input: favorites and popular SFW ### Response:"],
|
120 |
+
["### Instruction: Provide tips on stable diffusion to optimize low token prompts and enhance quality include prompt example. ### Response:"],
|
121 |
],
|
122 |
)
|
123 |
|
|
|
128 |
gr.Markdown(LICENSE)
|
129 |
|
130 |
if __name__ == "__main__":
|
131 |
+
demo.queue(max_size=20).launch()
|