Update app.py
Browse files
app.py
CHANGED
@@ -11,3 +11,24 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
11 |
)
|
12 |
|
13 |
tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-7b-instruct")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
)
|
12 |
|
13 |
tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-7b-instruct")
|
14 |
+
|
15 |
+
def generate_text(input_text):
|
16 |
+
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
17 |
+
attention_mask = torch.ones(input_ids.shape)
|
18 |
+
|
19 |
+
output = model.generate(
|
20 |
+
input_ids,
|
21 |
+
attention_mask=attention_mask,
|
22 |
+
max_length=200,
|
23 |
+
do_sample=True,
|
24 |
+
top_k=10,
|
25 |
+
num_return_sequences=1,
|
26 |
+
eos_token_id=tokenizer.eos_token_id,
|
27 |
+
)
|
28 |
+
|
29 |
+
output_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
30 |
+
print(output_text)
|
31 |
+
|
32 |
+
# Remove Prompt Echo from Generated Text
|
33 |
+
cleaned_output_text = output_text.replace(input_text, "")
|
34 |
+
return cleaned_output_text
|