2023/09/10
BingとBardの画像認識を比較する(3)
前回はWindowsのFormアプリの画面の「手書きデザイン」から生成AIでプログラムを書いてもらいました。言語は.NET系のC#でしたが、Bing-AI、Bardの両者、甲乙付けられないほど賢い回答を返してくれました。今回は、PythonでGUIも作成してもらいました。1. Bing-AI
プロンプトは以下の通りです。


# Import tkinter module追加・修正をした箇所は以下の通りです。
import tkinter as tk
import tkinter.ttk as ttk ## added ##
# Create a root window
root = tk.Tk()
# Create a frame to hold the widgets
frame = tk.Frame(root)
frame.pack()
# Create a label for the combo box
combo_label = tk.Label(frame, text="Combo Box")
combo_label.grid(row=0, column=0)
# Create a list of items for the combo box
items = ["Tokyo", "Osaka", "Nagoya", "Fukuoka", "Sapporo"]
# Create a variable to store the selected item
selected_item = tk.StringVar()
# Create a combo box with the items and the variable
#combo_box = tk.Combobox(frame, values=items, textvariable=selected_item)
combo_box = ttk.Combobox(frame, values=items, textvariable=selected_item)
combo_box.grid(row=1, column=0)
# Create a label for the text box
text_label = tk.Label(frame, text="Text Box")
text_label.grid(row=0, column=1)
# Create a variable to store the text content
text_content = tk.StringVar()
# Create a text box with the variable and a name
#text_box = tk.Entry(frame, textvariable=text_content, name="Disp-textBox")
text_box = tk.Entry(frame, textvariable=text_content) ## revised ##
text_box.grid(row=1, column=1)
# Define a function to display the selected item in the text box
def display():
# Get the selected item from the combo box
item = selected_item.get()
# Set the text content to the selected item
text_content.set(item)
# Create a button to call the display function
display_button = tk.Button(frame, text="Display", command=display)
display_button.grid(row=1, column=2)
# Start the main loop
root.mainloop()
1. 3行目を追加(23行目のエラーの対策)。
2. 23行目で「AttributeError: module 'tkinter' has no attribute 'Combobox'」のエラーが出たので、24行目に修正。
3. 36行目を37行目に修正。
実行結果です。

2. Google Bard
プロンプトはBingの時と同じで以下の通りです。



Bardの作成したプログラムもエラーを吐いたので一部修正を行いました。最終コードは以下の通りです。
import tkinter as tk追加・修正をした箇所は以下の通りです。
import tkinter.ttk as ttk ## added ##
root = tk.Tk()
root.title("Combobox Example")
# Create the combobox
#selection_combobox = tk.ttk.Combobox(root, values=["Tokyo", "Osaka", "Nagoya", "Fukuoka", "Sapporo"])
selection_combobox = ttk.Combobox(root, values=["Tokyo", "Osaka", "Nagoya", "Fukuoka", "Sapporo"]) ## revised ##
selection_combobox.grid(row=0, column=0)
# Create the display button
display_button = tk.Button(root, text="Display", command=lambda: display_text())
display_button.grid(row=1, column=0)
# Create the text box
disp_text_box = tk.Entry(root)
disp_text_box.grid(row=2, column=0)
def display_text():
# Get the selected item from the combobox
selected_item = selection_combobox.get()
# Display the selected item in the text box
disp_text_box.delete(0, tk.END) ## added ##
disp_text_box.insert(0, selected_item)
root.mainloop()
1. 2行目を追加(8行目のエラーの対策)。
2. 8行目で「AttributeError: module 'tkinter' has no attribute 'ttk'」のエラーが出たので、9行目に修正。
3. Displayボタンを押すと前回の表示が消えなかったため(下図参照)、26行目を追加。

前回に続いて、今回は同じ題目をPythonで試しました。追加・修正はBing-AI、Bardともにありましたが、両者、軽微なもので、今回も甲乙付けられないほど賢い結果でした。すごいですね・・。
スポンサーサイト
コメント