s2337a commited on
Commit
8660142
·
verified ·
1 Parent(s): 0f7a6a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -14
app.py CHANGED
@@ -1,4 +1,3 @@
1
- # Hugging Face 모델 로드
2
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
  import streamlit as st
4
  import os
@@ -11,21 +10,12 @@ model = AutoModelForSequenceClassification.from_pretrained("snunlp/KR-FinBert-SC
11
 
12
  # 환경 변수 설정
13
  os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0' # oneDNN 최적화 비활성화
 
14
 
15
  # 로그 초기화
16
  logging.set_verbosity(logging.INFO)
17
  logging.use_absl_handler()
18
 
19
- # GPU 설정
20
- gpus = tf.config.experimental.list_physical_devices('GPU')
21
- if gpus:
22
- try:
23
- for gpu in gpus:
24
- tf.config.experimental.set_memory_growth(gpu, True)
25
- print("GPU 메모리 증가 허용 설정 완료")
26
- except RuntimeError as e:
27
- print(f"GPU 설정 오류: {e}")
28
-
29
  # TensorFlow 정보 출력
30
  print("TensorFlow 버전:", tf.__version__)
31
  print("사용 가능한 장치:", tf.config.list_physical_devices())
@@ -37,6 +27,9 @@ st.write("This is a sample Streamlit app.")
37
  # 입력 필드 추가
38
  input_text = st.text_input("Enter some text:")
39
  if st.button("Analyze"):
40
- inputs = tokenizer(input_text, return_tensors="pt")
41
- outputs = model(**inputs)
42
- st.write("Model Output:", outputs.logits.tolist())
 
 
 
 
 
1
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
2
  import streamlit as st
3
  import os
 
10
 
11
  # 환경 변수 설정
12
  os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0' # oneDNN 최적화 비활성화
13
+ os.environ["CUDA_VISIBLE_DEVICES"] = "-1" # GPU 비활성화 (필요 시)
14
 
15
  # 로그 초기화
16
  logging.set_verbosity(logging.INFO)
17
  logging.use_absl_handler()
18
 
 
 
 
 
 
 
 
 
 
 
19
  # TensorFlow 정보 출력
20
  print("TensorFlow 버전:", tf.__version__)
21
  print("사용 가능한 장치:", tf.config.list_physical_devices())
 
27
  # 입력 필드 추가
28
  input_text = st.text_input("Enter some text:")
29
  if st.button("Analyze"):
30
+ try:
31
+ inputs = tokenizer(input_text, return_tensors="pt")
32
+ outputs = model(**inputs)
33
+ st.write("Model Output:", outputs.logits.tolist())
34
+ except Exception as e:
35
+ st.error(f"Error during model inference: {e}")