Spaces:
Sleeping
Sleeping
JackLiuCrypto
commited on
initial version
Browse files- app.py +38 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
import torch
|
5 |
+
from peft import PeftModel, PeftConfig
|
6 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
7 |
+
|
8 |
+
|
9 |
+
peft_model_id = "JackLiuAngel/bloom-7b1-lora-alfred-team-20240730"
|
10 |
+
config = PeftConfig.from_pretrained(peft_model_id)
|
11 |
+
model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path, return_dict=True, load_in_8bit=True, device_map='auto')
|
12 |
+
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
|
13 |
+
|
14 |
+
# Load the Lora model
|
15 |
+
model = PeftModel.from_pretrained(model, peft_model_id)
|
16 |
+
|
17 |
+
# sentiment_pipeline = pipeline("sentiment-analysis")
|
18 |
+
|
19 |
+
st.title("Team info finetuned in bigscience/bloom-7b1")
|
20 |
+
st.write("ask a question about our team:")
|
21 |
+
|
22 |
+
user_input = st.text_input("")
|
23 |
+
|
24 |
+
|
25 |
+
|
26 |
+
if user_input:
|
27 |
+
batch = tokenizer(f"“{user_input}” ->: ", return_tensors='pt')
|
28 |
+
|
29 |
+
with torch.cuda.amp.autocast():
|
30 |
+
output_tokens = model.generate(**batch, max_new_tokens=50)
|
31 |
+
|
32 |
+
# print('\n\n', tokenizer.decode(output_tokens[0], skip_special_tokens=True))
|
33 |
+
|
34 |
+
|
35 |
+
result = tokenizer.decode(output_tokens[0], skip_special_tokens=True)
|
36 |
+
|
37 |
+
|
38 |
+
st.write(f"reply: {result}")
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
transformers
|
3 |
+
torch
|