Spaces:
Sleeping
Sleeping
Benjamin Gonzalez
commited on
Commit
·
f997799
1
Parent(s):
1716229
prevent short length
Browse files
app.py
CHANGED
@@ -7,10 +7,12 @@ model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2", torch_dtype=torc
|
|
7 |
|
8 |
def generate(prompt, length):
|
9 |
inputs = tokenizer(prompt, return_tensors="pt", return_attention_mask=False)
|
|
|
|
|
10 |
outputs = model.generate(**inputs, max_length=length)
|
11 |
return tokenizer.batch_decode(outputs)[0]
|
12 |
|
13 |
-
demo = gr.Interface(fn=generate, inputs=["text", "
|
14 |
|
15 |
if __name__ == "__main__":
|
16 |
demo.launch(show_api=False)
|
|
|
7 |
|
8 |
def generate(prompt, length):
|
9 |
inputs = tokenizer(prompt, return_tensors="pt", return_attention_mask=False)
|
10 |
+
if length < inputs.length:
|
11 |
+
length = inputs.length
|
12 |
outputs = model.generate(**inputs, max_length=length)
|
13 |
return tokenizer.batch_decode(outputs)[0]
|
14 |
|
15 |
+
demo = gr.Interface(fn=generate, inputs=["text", gr.Number(value=50, label="max length",maximum=200)], outputs="text")
|
16 |
|
17 |
if __name__ == "__main__":
|
18 |
demo.launch(show_api=False)
|