Spaces:
Runtime error
Runtime error
shivam9980
commited on
Commit
•
b79b0fa
1
Parent(s):
55fa764
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,14 @@
|
|
1 |
# Load model directly
|
2 |
import streamlit as st
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
10 |
|
11 |
# alpaca_prompt = You MUST copy from above!
|
12 |
|
@@ -20,20 +22,22 @@ alpaca_prompt = """Below is an instruction that describes a task, paired with an
|
|
20 |
### Response:
|
21 |
{}"""
|
22 |
|
23 |
-
|
|
|
|
|
24 |
inputs = tokenizer(
|
25 |
[
|
26 |
alpaca_prompt.format(
|
27 |
"The following passage is content from a news report. Please summarize this passage in one sentence or less.", # instruction
|
28 |
-
|
29 |
"", # output - leave this blank for generation!
|
30 |
)
|
31 |
], return_tensors = "pt").to("cuda")
|
32 |
|
33 |
outputs = model.generate(**inputs, max_new_tokens = 64, use_cache = True)
|
34 |
-
results= tokenizer.batch_decode(outputs)
|
35 |
out = results[0].split('\n')[-1]
|
36 |
-
st.text_area(label='Headline',value=out[:
|
37 |
|
38 |
|
39 |
|
|
|
1 |
# Load model directly
|
2 |
import streamlit as st
|
3 |
+
from unsloth import FastLanguageModel
|
4 |
+
import torch
|
5 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
6 |
+
model_name = "shivam9980/mistral-7b-news-cnn-merged", # Choose ANY! eg teknium/OpenHermes-2.5-Mistral-7B
|
7 |
+
max_seq_length = max_seq_length,
|
8 |
+
dtype = dtype,
|
9 |
+
load_in_4bit = load_in_4bit,
|
10 |
+
token = hf_token, # use one if using gated models like meta-llama/Llama-2-7b-hf
|
11 |
+
)
|
12 |
|
13 |
# alpaca_prompt = You MUST copy from above!
|
14 |
|
|
|
22 |
### Response:
|
23 |
{}"""
|
24 |
|
25 |
+
# alpaca_prompt = Copied from above
|
26 |
+
c = st.text_input('Enter the contents ')
|
27 |
+
FastLanguageModel.for_inference(model) # Enable native 2x faster inference
|
28 |
inputs = tokenizer(
|
29 |
[
|
30 |
alpaca_prompt.format(
|
31 |
"The following passage is content from a news report. Please summarize this passage in one sentence or less.", # instruction
|
32 |
+
c,
|
33 |
"", # output - leave this blank for generation!
|
34 |
)
|
35 |
], return_tensors = "pt").to("cuda")
|
36 |
|
37 |
outputs = model.generate(**inputs, max_new_tokens = 64, use_cache = True)
|
38 |
+
results = tokenizer.batch_decode(outputs)
|
39 |
out = results[0].split('\n')[-1]
|
40 |
+
st.text_area(label='Headline',value=out[:])
|
41 |
|
42 |
|
43 |
|