-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
61 lines (46 loc) · 1.71 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import tkinter as tk
from tkinter import filedialog
from PIL import Image, ImageTk
import predict
def get_file_path():
file_path = filedialog.askopenfilename()
global file_path_predict
file_path_predict = file_path
return file_path
# Function to handle image selection
def select_image():
file_path = get_file_path()
caption_label.config(text="Caption will appear here...")
if file_path:
# Load the image
image = Image.open(file_path)
image.thumbnail((500, 500)) # Resize for display
photo = ImageTk.PhotoImage(image)
# Display the image
image_label.config(image=photo)
image_label.image = photo # Keep a reference!
# Function to generate image caption
def generate_caption():
caption = predict.generate_caption(file_path_predict)
caption_label.config(text=caption)
# the Google gTTs voice package
gTTs.run_gTTs(True, caption)
if __name__ == '__main__':
# Create the main window
root = tk.Tk()
root.title("Image Captioning GUI")
root.geometry('500x600')
# Create a label to display the image
image_label = tk.Label(root)
image_label.pack()
# Create a button to select an image
select_button = tk.Button(root, text="Select Image", command=select_image)
select_button.pack()
# Create a label to display the caption
caption_label = tk.Label(root, text="Caption will appear here...")
caption_label.pack()
# Create a button to generate the caption
generate_button = tk.Button(root, text="Generate Caption", command=generate_caption)
generate_button.pack()
# Start the GUI event loop
root.mainloop()