zswwsz commited on
Commit
cdd28fa
1 Parent(s): 7ade7f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -28,24 +28,23 @@ def preprocess(temp):
28
  return temp
29
 
30
  def classify_text(inp):
31
- print(inp)
32
  inp = preprocess(inp)
33
- print(inp)
34
  inp = tokenizer(inp, padding=True, max_length=512, truncation=True, return_tensors="pt")
35
- print(inp)
36
  with torch.no_grad():
37
  logits = model(**inp).logits
38
- print(logits)
39
- print(logits.shape)
40
  # logits = logits.argsort().squeeze(0)
41
  logits = torch.nn.Softmax(dim=1)(logits).squeeze(0)
42
- print(logits)
43
  return {labels[i]: float(logits[i].item()) for i in range(len(labels))}
44
  # return {logits.argmax().item() : labels[logits.argmax().item()]}
45
 
46
  input = '明天又是好日子\n千金的光阴不能等\n明天又是好日子\n赶上了盛世咱享太平\n今天是个好日子\n心想的事儿都能成\n明天又是好日子\n千金的光阴不能等\n今天明天都是好日子\n赶上了盛世咱享太平'
47
 
48
-
49
  gr.Interface(
50
  classify_text,
51
  # gr.inputs.Image(),
@@ -54,4 +53,4 @@ gr.Interface(
54
  # inputs='image',
55
  # outputs='label',
56
  # examples=[["images/cheetah1.jpg"], ["images/lion.jpg"]],
57
- ).launch(debug=True)
 
28
  return temp
29
 
30
  def classify_text(inp):
31
+ # print(inp)
32
  inp = preprocess(inp)
33
+ # print(inp)
34
  inp = tokenizer(inp, padding=True, max_length=512, truncation=True, return_tensors="pt")
35
+ # print(inp)
36
  with torch.no_grad():
37
  logits = model(**inp).logits
38
+ # print(logits)
39
+ # print(logits.shape)
40
  # logits = logits.argsort().squeeze(0)
41
  logits = torch.nn.Softmax(dim=1)(logits).squeeze(0)
42
+ # print(logits)
43
  return {labels[i]: float(logits[i].item()) for i in range(len(labels))}
44
  # return {logits.argmax().item() : labels[logits.argmax().item()]}
45
 
46
  input = '明天又是好日子\n千金的光阴不能等\n明天又是好日子\n赶上了盛世咱享太平\n今天是个好日子\n心想的事儿都能成\n明天又是好日子\n千金的光阴不能等\n今天明天都是好日子\n赶上了盛世咱享太平'
47
 
 
48
  gr.Interface(
49
  classify_text,
50
  # gr.inputs.Image(),
 
53
  # inputs='image',
54
  # outputs='label',
55
  # examples=[["images/cheetah1.jpg"], ["images/lion.jpg"]],
56
+ ).launch(debug=True,share=True)