ydshieh commited on
Commit
76136cc
1 Parent(s): 241d776

add en translation

Browse files
Files changed (3) hide show
  1. app.py +4 -2
  2. model.py +5 -0
  3. requirements.txt +2 -1
app.py CHANGED
@@ -45,8 +45,10 @@ with st.spinner('Generating image caption ...'):
45
 
46
  caption = predict(image)
47
  image.close()
48
- # st.success(f'{caption}')
49
- st.header(f'{caption}')
 
 
50
 
51
  st.sidebar.header("ViT-GPT2 predicts:")
52
  st.sidebar.write(f"{caption}", '\n')
 
45
 
46
  caption = predict(image)
47
  image.close()
48
+ caption_en = translator.translate(caption, src='fr', dest='en')
49
+ st.header('Prediction:')
50
+ st.subheader(f'{caption}\n')
51
+ st.subheader(f'English Translation: {caption_en}\n')
52
 
53
  st.sidebar.header("ViT-GPT2 predicts:")
54
  st.sidebar.write(f"{caption}", '\n')
model.py CHANGED
@@ -7,6 +7,9 @@ from transformers import ViTFeatureExtractor
7
  from transformers import GPT2Tokenizer
8
  from huggingface_hub import hf_hub_download
9
 
 
 
 
10
  current_path = os.path.dirname(os.path.abspath(__file__))
11
  sys.path.append(current_path)
12
 
@@ -57,6 +60,8 @@ def predict(image):
57
  while ' ' in caption:
58
  caption = caption.replace(' ', ' ')
59
  caption = caption.strip()
 
 
60
 
61
  return caption
62
 
 
7
  from transformers import GPT2Tokenizer
8
  from huggingface_hub import hf_hub_download
9
 
10
+ from googletrans import Translator
11
+ translator = Translator()
12
+
13
  current_path = os.path.dirname(os.path.abspath(__file__))
14
  sys.path.append(current_path)
15
 
 
60
  while ' ' in caption:
61
  caption = caption.replace(' ', ' ')
62
  caption = caption.strip()
63
+ if caption:
64
+ caption = caption[0].upper() + caption[1:]
65
 
66
  return caption
67
 
requirements.txt CHANGED
@@ -3,4 +3,5 @@ Pillow
3
  jax[cpu]
4
  flax
5
  transformers
6
- huggingface_hub
 
 
3
  jax[cpu]
4
  flax
5
  transformers
6
+ huggingface_hub
7
+ googletrans==4.0.0-rc1