thamada commited on
Commit
56efc99
1 Parent(s): 04586f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -1
app.py CHANGED
@@ -1,7 +1,30 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  def display_message():
4
- return "こんにちは"
 
5
 
6
  iface = gr.Interface(fn=display_message, inputs=None, outputs="text")
7
  iface.launch()
 
1
  import gradio as gr
2
+ import torch
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer
4
+
5
+ def runLLM ():
6
+ model = AutoModelForCausalLM.from_pretrained("cyberagent/open-calm-small", device_map="auto", torch_dtype=torch.float16)
7
+ tokenizer = AutoTokenizer.from_pretrained("cyberagent/open-calm-small")
8
+
9
+ inputs = tokenizer("AIによって私達の暮らしは、", return_tensors="pt").to(model.device)
10
+
11
+ with torch.no_grad():
12
+ tokens = model.generate(
13
+ **inputs,
14
+ max_new_tokens=64,
15
+ do_sample=True,
16
+ temperature=0.7,
17
+ top_p=0.9,
18
+ repetition_penalty=1.05,
19
+ pad_token_id=tokenizer.pad_token_id,
20
+ )
21
+
22
+ output = tokenizer.decode(tokens[0], skip_special_tokens=True)
23
+ return output
24
 
25
  def display_message():
26
+ msg = runLLM()
27
+ return msg
28
 
29
  iface = gr.Interface(fn=display_message, inputs=None, outputs="text")
30
  iface.launch()