matthew chung commited on
Commit
597364b
1 Parent(s): cb5a9ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -2
app.py CHANGED
@@ -1,4 +1,41 @@
1
  import streamlit as st
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
 
3
+ import torch
4
+ import transformers
5
+ from peft import PeftModel, PeftConfig
6
+ from transformers import AutoModelForCausalLM, AutoTokenizer
7
+
8
+ import os
9
+ import torch
10
+ import torch.nn as nn
11
+ import bitsandbytes as bnb
12
+ from transformers import AutoTokenizer, AutoConfig, AutoModelForCausalLM
13
+
14
+ from datasets import Dataset
15
+ import pandas as pd
16
+ import transformers
17
+ from datasets import load_dataset
18
+ from peft import LoraConfig, get_peft_model
19
+
20
+ import time
21
+ import logging
22
+
23
+ peft_model_id = "foobar8675/bloom-7b1-lora-tagger"
24
+ config = PeftConfig.from_pretrained(peft_model_id)
25
+ model = AutoModelForCausalLM.from_pretrained("bigscience/bloom-7b1", return_dict=True, load_in_8bit=True, device_map='auto')
26
+ tokenizer = AutoTokenizer.from_pretrained("bigscience/bloom-7b1")
27
+
28
+ # # Load the Lora model
29
+ model = PeftModel.from_pretrained(model, peft_model_id)
30
+
31
+ text = st.text_area('enter text')
32
+
33
+ if text:
34
+
35
+ start_time = time.time()
36
+ batch = tokenizer("“FINDINGS: There is bilateral narrowing the femoral tibial joint mild on the right moderate on the left. There is scalloping of the lateral tibial plateau of the left knee with small subchondral cysts and sclerosis as well as lateral degenerative osteophyte formation. There is mild narrowing of the right patellofemoral joint and moderate narrowing of the left. Degenerative osteophytes arises from the posterior inferior margin of the left patella. There is a large well corticated 2.5 cm calcification adjacent to the anterior tibial tubercle of the proximal right tibia. There is no joint effusion. The soft tissues are normal. Mild scattered vascular calcifications are noted involving the distal left superficial femoral and popliteal arteries.” ->: ", return_tensors='pt')
37
+ output_tokens = model.generate(**batch, max_new_tokens=25)
38
+
39
+ out = tokenizer.decode(output_tokens[0], skip_special_tokens=True)
40
+ st.json(out)
41
+ st.json(f"Elapsed time: {time.time() - start_time}s")