jguimond commited on
Commit
4dfff9e
·
verified ·
1 Parent(s): 392f279

Add more commenting for header and sections

Browse files
Files changed (1) hide show
  1. app.py +29 -3
app.py CHANGED
@@ -1,3 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from transformers import pipeline, AutoTokenizer, AutoModelForImageTextToText
3
  from sentence_transformers import SentenceTransformer, util
@@ -5,12 +21,16 @@ import evaluate
5
  import warnings
6
  import logging
7
 
8
- # --- 0. Setup & Warning Suppression ---
9
  # Filter out the "FutureWarning" and "UserWarning" to keep the console clean
10
  warnings.filterwarnings("ignore", category=FutureWarning)
11
  warnings.filterwarnings("ignore", category=UserWarning)
12
  logging.getLogger("transformers").setLevel(logging.ERROR)
13
 
 
 
 
 
 
14
  # --- 1. Load Image Captioning Models ---
15
 
16
  # Model 1: BLIP (Base)
@@ -42,7 +62,11 @@ rouge = evaluate.load("rouge")
42
  # These cover: Peaceful dog, Sad funeral, Happy kids, Angry man, Scared people, Fighting tigers
43
  VIBE_LABELS = ["Peaceful/Calm", "Happy/Joy", "Sad/Sorrow", "Angry/Upset", "Fear/Scared", "Action/Violence"]
44
 
45
- # --- 3. Analysis Function ---
 
 
 
 
46
  def analyze_image(image, ground_truth):
47
 
48
  # -- A. Generate Captions --
@@ -112,7 +136,9 @@ def analyze_image(image, ground_truth):
112
 
113
  return out1, out2, stats
114
 
115
- # --- 4. Interface ---
 
 
116
 
117
  # Define Inputs
118
  image_input = gr.Image(type="pil", label="Upload Image")
 
1
+ # ==============================================================================
2
+ # Josh Guimond
3
+ # Unit 8 Assignment: End-to-End AI Solution Implementation
4
+ # ARIN 460
5
+ # 12/03/2025
6
+
7
+ # Description: This script implements a multimodal AI web app using Gradio to
8
+ # run two image captioning models, a text “vibe” classifier, and NLP metrics on
9
+ # uploaded images, allowing direct comparison of model captions to ground-truth
10
+ # descriptions.
11
+ # ==============================================================================
12
+
13
+ # ==============================================================================
14
+ # SECTION 1: SETUP & INSTALLATIONS
15
+ # ==============================================================================
16
+ # Install libraries
17
  import gradio as gr
18
  from transformers import pipeline, AutoTokenizer, AutoModelForImageTextToText
19
  from sentence_transformers import SentenceTransformer, util
 
21
  import warnings
22
  import logging
23
 
 
24
  # Filter out the "FutureWarning" and "UserWarning" to keep the console clean
25
  warnings.filterwarnings("ignore", category=FutureWarning)
26
  warnings.filterwarnings("ignore", category=UserWarning)
27
  logging.getLogger("transformers").setLevel(logging.ERROR)
28
 
29
+
30
+ # ==============================================================================
31
+ # SECTION 2: LOAD MODELS
32
+ # ==============================================================================
33
+
34
  # --- 1. Load Image Captioning Models ---
35
 
36
  # Model 1: BLIP (Base)
 
62
  # These cover: Peaceful dog, Sad funeral, Happy kids, Angry man, Scared people, Fighting tigers
63
  VIBE_LABELS = ["Peaceful/Calm", "Happy/Joy", "Sad/Sorrow", "Angry/Upset", "Fear/Scared", "Action/Violence"]
64
 
65
+ # ==============================================================================
66
+ # SECTION 3: ANALYSIS FUNCTIONS
67
+ # ==============================================================================
68
+
69
+ # --- Analysis Function ---
70
  def analyze_image(image, ground_truth):
71
 
72
  # -- A. Generate Captions --
 
136
 
137
  return out1, out2, stats
138
 
139
+ # ==============================================================================
140
+ # SECTION 4: GRADIO INTERFACE
141
+ # ==============================================================================
142
 
143
  # Define Inputs
144
  image_input = gr.Image(type="pil", label="Upload Image")