OzoneAsai commited on
Commit
eb47558
·
1 Parent(s): a6c7076

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import os
2
 
3
  # コマンドを実行する
4
- os.system("pip install transformers torch")
5
 
6
  # コマンドの実行結果を取得する(stdoutとstderrは出力されない)
7
  result = os.system("pip install transformers")
@@ -16,7 +16,13 @@ model = AutoModel.from_pretrained("Tanrei/GPTSAN-japanese").to(device)
16
  tokenizer = AutoTokenizer.from_pretrained("Tanrei/GPTSAN-japanese")
17
  trainer_utils.set_seed(30)
18
 
 
 
 
 
 
19
  def generate_text(input_text):
 
20
  x_token = tokenizer("", prefix_text=input_text, return_tensors="pt")
21
  input_ids = x_token.input_ids.to(device)
22
  token_type_ids = x_token.token_type_ids.to(device)
@@ -27,11 +33,15 @@ def generate_text(input_text):
27
  input_text = gr.inputs.Textbox(lines=5, label="Input Text")
28
  output_text = gr.outputs.Textbox(label="Generated Text")
29
 
 
 
 
 
30
  interface = gr.Interface(
31
  fn=generate_text,
32
  inputs=input_text,
33
  outputs=output_text,
34
- title="Japanese Text Generation",
35
  description="Enter a prompt in Japanese to generate text."
36
  )
37
  interface.launch()
 
1
  import os
2
 
3
  # コマンドを実行する
4
+ os.system("pip install transformers torch psutil")
5
 
6
  # コマンドの実行結果を取得する(stdoutとstderrは出力されない)
7
  result = os.system("pip install transformers")
 
16
  tokenizer = AutoTokenizer.from_pretrained("Tanrei/GPTSAN-japanese")
17
  trainer_utils.set_seed(30)
18
 
19
+ def get_memory_usage():
20
+ process = psutil.Process()
21
+ memory_usage = process.memory_info().rss / 1024 / 1024 # メモリ使用量をMB単位で取得
22
+ return f"Memory Usage: {memory_usage:.2f} MB"
23
+
24
  def generate_text(input_text):
25
+ usag=get_memory_usage()
26
  x_token = tokenizer("", prefix_text=input_text, return_tensors="pt")
27
  input_ids = x_token.input_ids.to(device)
28
  token_type_ids = x_token.token_type_ids.to(device)
 
33
  input_text = gr.inputs.Textbox(lines=5, label="Input Text")
34
  output_text = gr.outputs.Textbox(label="Generated Text")
35
 
36
+
37
+
38
+
39
+
40
  interface = gr.Interface(
41
  fn=generate_text,
42
  inputs=input_text,
43
  outputs=output_text,
44
+ title=usag,
45
  description="Enter a prompt in Japanese to generate text."
46
  )
47
  interface.launch()