Bondya commited on
Commit
8322a04
·
verified ·
1 Parent(s): 86cd9e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -8,7 +8,8 @@ import os
8
  def img2text(img_path):
9
  captioner = pipeline(
10
  "image-to-text",
11
- model="Salesforce/blip-image-captioning-base"
 
12
  )
13
  result = captioner(img_path)
14
  return result[0]["generated_text"]
@@ -16,11 +17,11 @@ def img2text(img_path):
16
  def text2story(scenario):
17
  generator = pipeline(
18
  "text-generation",
19
- model="gpt2-medium",
20
  trust_remote_code=True,
21
  device_map="auto", # 必须添加
22
  torch_dtype=torch.float16,
23
- max_length=150,
24
  num_return_sequences=1
25
  )
26
  prompt = f"Create a children's story based on: {scenario}"
 
8
  def img2text(img_path):
9
  captioner = pipeline(
10
  "image-to-text",
11
+ model="nlpconnect/vit-gpt2-image-captioning",
12
+ device_map="auto"
13
  )
14
  result = captioner(img_path)
15
  return result[0]["generated_text"]
 
17
  def text2story(scenario):
18
  generator = pipeline(
19
  "text-generation",
20
+ model="gpt2",
21
  trust_remote_code=True,
22
  device_map="auto", # 必须添加
23
  torch_dtype=torch.float16,
24
+ max_length=100,
25
  num_return_sequences=1
26
  )
27
  prompt = f"Create a children's story based on: {scenario}"