Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -30,7 +30,6 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
30 |
torch_dtype=torch.bfloat16,
|
31 |
)
|
32 |
model.eval()
|
33 |
-
|
34 |
@spaces.GPU(duration=90)
|
35 |
def generate(
|
36 |
message: str,
|
@@ -61,89 +60,87 @@ def generate(
|
|
61 |
t = Thread(target=model.generate, kwargs=generate_kwargs)
|
62 |
t.start()
|
63 |
|
64 |
-
|
65 |
for text in streamer:
|
66 |
-
|
67 |
-
yield
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
)
|
121 |
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
repetition_penalty
|
133 |
-
],
|
134 |
-
outputs=output_box
|
135 |
-
)
|
136 |
-
|
137 |
-
gr.Examples(
|
138 |
-
examples=[
|
139 |
-
"Hello there! How are you doing?",
|
140 |
-
"Can you explain briefly to me what is the Python programming language?",
|
141 |
-
"Explain the plot of Cinderella in a sentence.",
|
142 |
-
"How many hours does it take a man to eat a Helicopter?",
|
143 |
-
"Write a 100-word article on 'Benefits of Open-Source in AI research'",
|
144 |
-
],
|
145 |
-
inputs=input_box
|
146 |
-
)
|
147 |
|
148 |
if __name__ == "__main__":
|
149 |
demo.queue(max_size=20).launch()
|
|
|
30 |
torch_dtype=torch.bfloat16,
|
31 |
)
|
32 |
model.eval()
|
|
|
33 |
@spaces.GPU(duration=90)
|
34 |
def generate(
|
35 |
message: str,
|
|
|
60 |
t = Thread(target=model.generate, kwargs=generate_kwargs)
|
61 |
t.start()
|
62 |
|
63 |
+
full_message = message
|
64 |
for text in streamer:
|
65 |
+
full_message += text
|
66 |
+
yield full_message
|
67 |
+
with gr.Blocks(css="style.css", fill_height=True) as demo:
|
68 |
+
gr.Markdown(DESCRIPTION)
|
69 |
+
gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
|
70 |
+
|
71 |
+
with gr.Row():
|
72 |
+
with gr.Column(scale=4):
|
73 |
+
text_box = gr.Textbox(
|
74 |
+
label="Enter your text",
|
75 |
+
placeholder="Type your message here...",
|
76 |
+
lines=10
|
77 |
+
)
|
78 |
+
with gr.Column(scale=1):
|
79 |
+
max_new_tokens = gr.Slider(
|
80 |
+
label="Max new tokens",
|
81 |
+
minimum=1,
|
82 |
+
maximum=MAX_MAX_NEW_TOKENS,
|
83 |
+
step=1,
|
84 |
+
value=DEFAULT_MAX_NEW_TOKENS,
|
85 |
+
)
|
86 |
+
temperature = gr.Slider(
|
87 |
+
label="Temperature",
|
88 |
+
minimum=0.1,
|
89 |
+
maximum=4.0,
|
90 |
+
step=0.1,
|
91 |
+
value=0.6,
|
92 |
+
)
|
93 |
+
top_p = gr.Slider(
|
94 |
+
label="Top-p (nucleus sampling)",
|
95 |
+
minimum=0.05,
|
96 |
+
maximum=1.0,
|
97 |
+
step=0.05,
|
98 |
+
value=0.9,
|
99 |
+
)
|
100 |
+
top_k = gr.Slider(
|
101 |
+
label="Top-k",
|
102 |
+
minimum=1,
|
103 |
+
maximum=1000,
|
104 |
+
step=1,
|
105 |
+
value=50,
|
106 |
+
)
|
107 |
+
repetition_penalty = gr.Slider(
|
108 |
+
label="Repetition penalty",
|
109 |
+
minimum=1.0,
|
110 |
+
maximum=2.0,
|
111 |
+
step=0.05,
|
112 |
+
value=1.2,
|
113 |
+
)
|
114 |
+
|
115 |
+
with gr.Row():
|
116 |
+
complete_btn = gr.Button("Complete")
|
117 |
+
stop_btn = gr.Button("Stop Generation")
|
118 |
+
|
119 |
+
stop_click = stop_btn.click(fn=None, cancels=[complete_btn.click])
|
120 |
+
|
121 |
+
complete_btn.click(
|
122 |
+
fn=generate,
|
123 |
+
inputs=[
|
124 |
+
text_box,
|
125 |
+
max_new_tokens,
|
126 |
+
temperature,
|
127 |
+
top_p,
|
128 |
+
top_k,
|
129 |
+
repetition_penalty
|
130 |
+
],
|
131 |
+
outputs=text_box
|
132 |
)
|
133 |
|
134 |
+
gr.Examples(
|
135 |
+
examples=[
|
136 |
+
"Hello there! How are you doing?",
|
137 |
+
"Can you explain briefly to me what is the Python programming language?",
|
138 |
+
"Explain the plot of Cinderella in a sentence.",
|
139 |
+
"How many hours does it take a man to eat a Helicopter?",
|
140 |
+
"Write a 100-word article on 'Benefits of Open-Source in AI research'",
|
141 |
+
],
|
142 |
+
inputs=text_box
|
143 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
|
145 |
if __name__ == "__main__":
|
146 |
demo.queue(max_size=20).launch()
|