jhl001 commited on
Commit
b80f360
โ€ข
1 Parent(s): 22fe41d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -1
app.py CHANGED
@@ -1,7 +1,27 @@
1
  import gradio as gr
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  def greet(name):
4
- return "Hello " + name + "!!"
 
 
5
 
6
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
  iface.launch()
 
1
  import gradio as gr
2
 
3
+ import torch
4
+ from transformers import AutoModelForCausalLM, AutoTokenizer
5
+
6
+ model = AutoModelForCausalLM.from_pretrained("cyberagent/open-calm-7b", device_map="auto", torch_dtype=torch.float16)
7
+ tokenizer = AutoTokenizer.from_pretrained("cyberagent/open-calm-7b")
8
+
9
+ def proc( inputs ):
10
+ with torch.no_grad():
11
+ tokens = model.generate(
12
+ **inputs,
13
+ max_new_tokens=64, # ็”Ÿๆˆใ™ใ‚‹้•ทใ•. 128 ใจใ‹ใงใ‚‚่‰ฏใ„.
14
+ do_sample=True,
15
+ temperature=0.7, # ็”Ÿๆˆใฎใƒฉใƒณใƒ€ใƒ ๆ€ง. ้ซ˜ใ„ใปใฉๆง˜ใ€…ใชๅ˜่ชžใŒๅ‡บใฆใใ‚‹ใŒ้–ข้€ฃๆ€งใฏไธ‹ใŒใ‚‹.
16
+ pad_token_id=tokenizer.pad_token_id,
17
+ )
18
+
19
+ return = tokenizer.decode(tokens[0], skip_special_tokens=True)
20
+
21
  def greet(name):
22
+ inputs = tokenizer(name, return_tensors="pt").to(model.device)
23
+ outputs = proc( inputs )
24
+ return( outputs )
25
 
26
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
27
  iface.launch()