Spaces:
Runtime error
Runtime error
Commit
•
9f978c0
1
Parent(s):
2db067e
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ import torch
|
|
6 |
openelm_270m_instruct = AutoModelForCausalLM.from_pretrained("apple/OpenELM-270M-Instruct", trust_remote_code=True)
|
7 |
tokenizer = AutoTokenizer.from_pretrained("NousResearch/Llama-2-7b-hf")
|
8 |
|
9 |
-
def generate(newQuestion):
|
10 |
tokenized_prompt = tokenizer(newQuestion)
|
11 |
tokenized_prompt = torch.tensor(
|
12 |
tokenized_prompt['input_ids'],
|
@@ -16,7 +16,7 @@ def generate(newQuestion):
|
|
16 |
# Generate
|
17 |
output_ids = openelm_270m_instruct.generate(
|
18 |
tokenized_prompt,
|
19 |
-
max_length=
|
20 |
pad_token_id=0,
|
21 |
)
|
22 |
output_text = tokenizer.decode(
|
@@ -34,12 +34,12 @@ apple/OpenELM-270M-Instruct
|
|
34 |
"""
|
35 |
|
36 |
|
37 |
-
def greet(name):
|
38 |
-
return generate(name)
|
39 |
|
40 |
iface = gr.Interface(
|
41 |
fn=greet,
|
42 |
-
inputs=Textbox(label="Enter Text Here:", type="text"),
|
43 |
outputs=[Textbox(label="generated answer:")],
|
44 |
title="OpenELM-270M-Instruct",
|
45 |
# Markdown(developer_info, elem_id="dev-info"), # Place Markdown directly
|
|
|
6 |
openelm_270m_instruct = AutoModelForCausalLM.from_pretrained("apple/OpenELM-270M-Instruct", trust_remote_code=True)
|
7 |
tokenizer = AutoTokenizer.from_pretrained("NousResearch/Llama-2-7b-hf")
|
8 |
|
9 |
+
def generate(newQuestion,num):
|
10 |
tokenized_prompt = tokenizer(newQuestion)
|
11 |
tokenized_prompt = torch.tensor(
|
12 |
tokenized_prompt['input_ids'],
|
|
|
16 |
# Generate
|
17 |
output_ids = openelm_270m_instruct.generate(
|
18 |
tokenized_prompt,
|
19 |
+
max_length=int(num),
|
20 |
pad_token_id=0,
|
21 |
)
|
22 |
output_text = tokenizer.decode(
|
|
|
34 |
"""
|
35 |
|
36 |
|
37 |
+
def greet(name,num):
|
38 |
+
return generate(name,num)
|
39 |
|
40 |
iface = gr.Interface(
|
41 |
fn=greet,
|
42 |
+
inputs=[Textbox(label="Enter Text Here:", type="text"),Textbox(label="number of generated tokens:", type="text")],
|
43 |
outputs=[Textbox(label="generated answer:")],
|
44 |
title="OpenELM-270M-Instruct",
|
45 |
# Markdown(developer_info, elem_id="dev-info"), # Place Markdown directly
|