Frantz103 commited on
Commit
65c6a4e
1 Parent(s): b5041b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -10
app.py CHANGED
@@ -17,7 +17,6 @@ import spacy
17
 
18
  import re
19
 
20
-
21
  # Initialize the processor and model for the large COCO model
22
  processor = AutoProcessor.from_pretrained("microsoft/git-large-coco")
23
  model = AutoModelForCausalLM.from_pretrained("microsoft/git-large-coco")
@@ -83,7 +82,6 @@ def extract_main_words(text):
83
  main_words = [token.lemma_ for token in doc if token.pos_ == 'NOUN']
84
  return main_words
85
 
86
-
87
  def get_topics(text):
88
  # Vectorize the text
89
  vectorizer = CountVectorizer()
@@ -109,8 +107,6 @@ def compute_similarity(caption1, caption2):
109
  similarity_score = cosine_sim[0, 1]
110
  return similarity_score
111
 
112
-
113
- # Cell 3
114
  def evaluate_caption(image, caption1, caption2, unique_refined_labels):
115
  # Scores initialization
116
  score_caption1 = 0
@@ -120,7 +116,6 @@ def evaluate_caption(image, caption1, caption2, unique_refined_labels):
120
  object_presence_score1 = 0
121
  object_presence_score2 = 0
122
 
123
-
124
  # Assume you have a function to extract main words
125
  main_words_caption1 = extract_main_words(caption1)
126
  main_words_caption2 = extract_main_words(caption2)
@@ -215,14 +210,13 @@ def process_image(image_path):
215
  # evealuate the captions
216
  better_caption = evaluate_caption(image, caption1, caption2, unique_refined_labels)
217
 
218
-
219
  return caption1, caption2, better_caption
220
 
221
  import gradio as gr
222
 
223
  img_cap_ui = gr.Interface(
224
  fn=process_image,
225
- title="Image Captioning with Automactic Evaluation",
226
  description="Caution: this is a research experiment for personal use, please review the captions before using.",
227
  inputs=gr.inputs.Image(type="filepath",label="Add your image"),
228
  outputs=[gr.Textbox(label="Caption from the git-coco model", show_copy_button=True),
@@ -234,6 +228,3 @@ img_cap_ui = gr.Interface(
234
  )
235
 
236
  img_cap_ui.launch()
237
-
238
-
239
-
 
17
 
18
  import re
19
 
 
20
  # Initialize the processor and model for the large COCO model
21
  processor = AutoProcessor.from_pretrained("microsoft/git-large-coco")
22
  model = AutoModelForCausalLM.from_pretrained("microsoft/git-large-coco")
 
82
  main_words = [token.lemma_ for token in doc if token.pos_ == 'NOUN']
83
  return main_words
84
 
 
85
  def get_topics(text):
86
  # Vectorize the text
87
  vectorizer = CountVectorizer()
 
107
  similarity_score = cosine_sim[0, 1]
108
  return similarity_score
109
 
 
 
110
  def evaluate_caption(image, caption1, caption2, unique_refined_labels):
111
  # Scores initialization
112
  score_caption1 = 0
 
116
  object_presence_score1 = 0
117
  object_presence_score2 = 0
118
 
 
119
  # Assume you have a function to extract main words
120
  main_words_caption1 = extract_main_words(caption1)
121
  main_words_caption2 = extract_main_words(caption2)
 
210
  # evealuate the captions
211
  better_caption = evaluate_caption(image, caption1, caption2, unique_refined_labels)
212
 
 
213
  return caption1, caption2, better_caption
214
 
215
  import gradio as gr
216
 
217
  img_cap_ui = gr.Interface(
218
  fn=process_image,
219
+ title="Image Captioning with Automatic Evaluation",
220
  description="Caution: this is a research experiment for personal use, please review the captions before using.",
221
  inputs=gr.inputs.Image(type="filepath",label="Add your image"),
222
  outputs=[gr.Textbox(label="Caption from the git-coco model", show_copy_button=True),
 
228
  )
229
 
230
  img_cap_ui.launch()