Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -18,19 +18,23 @@ quantization_config = BitsAndBytesConfig(load_in_8bit=True)
|
|
18 |
model = AutoModelForCausalLM.from_pretrained(model_path, device_map='cuda', quantization_config=quantization_config)
|
19 |
|
20 |
@spaces.GPU
|
21 |
-
def generate_text(
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
26 |
return generated_text
|
27 |
|
28 |
|
29 |
def gradio_app():
|
30 |
with gr.Blocks() as demo:
|
31 |
gr.Markdown(title)
|
32 |
-
|
33 |
-
|
34 |
with gr.Row():
|
35 |
temperature = gr.Slider(minimum=0.1, maximum=1.0, step=0.1, value=0.5, label="Temperature")
|
36 |
max_length = gr.Slider(minimum=250, maximum=1024, step=10, value=450, label="Generate Length")
|
@@ -39,7 +43,7 @@ def gradio_app():
|
|
39 |
|
40 |
generate_btn.click(
|
41 |
fn=generate_text,
|
42 |
-
inputs=[
|
43 |
outputs=output
|
44 |
)
|
45 |
|
|
|
18 |
model = AutoModelForCausalLM.from_pretrained(model_path, device_map='cuda', quantization_config=quantization_config)
|
19 |
|
20 |
@spaces.GPU
|
21 |
+
def generate_text(usertitle, content, max_new_tokens=512,model=model, tokenizer=tokenizer, temperature=0.7):
|
22 |
+
msg = [{
|
23 |
+
'title': title,
|
24 |
+
'content': content
|
25 |
+
}]
|
26 |
+
inputs = tokenizer.apply_chat_template((msg, return_tensors='pt').cuda())
|
27 |
+
generated_ids = model.generate(inputs['input_ids'], max_new_tokens=max_new_tokens, temperature=temperature, pad_token_id=tokenizer.eos_token_id)
|
28 |
+
generated_text = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
|
29 |
+
|
30 |
return generated_text
|
31 |
|
32 |
|
33 |
def gradio_app():
|
34 |
with gr.Blocks() as demo:
|
35 |
gr.Markdown(title)
|
36 |
+
usertitle = gr.Textbox(label="Title", value="Cortado", lines=1)
|
37 |
+
content = gr.Textbox(label="WordPhrases", value=examplecofee, lines=5)
|
38 |
with gr.Row():
|
39 |
temperature = gr.Slider(minimum=0.1, maximum=1.0, step=0.1, value=0.5, label="Temperature")
|
40 |
max_length = gr.Slider(minimum=250, maximum=1024, step=10, value=450, label="Generate Length")
|
|
|
43 |
|
44 |
generate_btn.click(
|
45 |
fn=generate_text,
|
46 |
+
inputs=[usertitle, content, temperature, max_length],
|
47 |
outputs=output
|
48 |
)
|
49 |
|