1、实例代码
import tkinter as tk
from tkinter import messagebox
from tkinter import ttk
import requests
def submit():
input_text = entry.get()
if len(input_text) == 0:
messagebox.showinfo("提示", "请输入您所要提问的问题!")
return
selected_value = combobox.get()
print("选择的值是:", selected_value)
print("您的问题是:", input_text)
if selected_value == "大模型召回":
messagebox.showinfo("提示", "提交后稍等片刻,请允许我疯狂计算一波!!!")
# messagebox.showinfo("免责声明", "产生的一切后果,由您自行承担!!!")
# 发起GET请求
response = requests.get('http://XXXXXX:3001/milvusQuery?question=' + input_text)
# 检查响应状态码
if response.status_code == 200:
# 获取响应数据
data = response.json()
print(data)
messagebox.showinfo("召回结果",data.get('result'))
else:
print("请求失败,状态码:", response.status_code)
elif selected_value == "向量召回":
messagebox.showinfo("提示", "提交后稍等片刻,请允许我疯狂计算一波!!!")
# messagebox.showinfo("免责声明", "产生的一切后果,由您自行承担!!!")
# 发起GET请求
response = requests.get('http://XXXXXX:3000/getChunkWithMilvus?topk=5&output_fields=pk,text&question=' + input_text)
# 检查响应状态码
if response.status_code == 200:
# 获取响应数据
data = response.json()
print(data)
messagebox.showinfo("召回结果", data.get('result'))
else:
print("请求失败,状态码:", response.status_code)
else:
messagebox.showinfo("提示", "嘿这个功能还没开发哦")
window = tk.Tk()
window.title("大模型召回小工具-小姐姐定制版")
# 获取屏幕宽度和高度
screen_width = window.winfo_screenwidth()
screen_height = window.winfo_screenheight()
# 设置窗口尺寸和位置
window_width = 800
window_height = 400
x = (screen_width - window_width) // 2
y = (screen_height - window_height) // 2
window.geometry(f"{window_width}x{window_height}+{x}+{y}")
options = ["向量召回", "大模型召回"]
options1 = ["小姐姐","小哥哥"]
# selected_option = tk.StringVar()
# selected_option.set(options[1])
# dropdown = ttk.OptionMenu(window, selected_option, *options)
# dropdown.pack()
label0 = tk.Label(window, text="召回内容:")
label0.pack() # 添加标签并设置间距
combobox = ttk.Combobox(window, values=options, width=20, height=10,name="召回内容")
combobox.current(1) # 设置默认选中的选项
combobox.pack(pady=10)
label0 = tk.Label(window, text="性别选择:")
label0.pack() # 添加标签并设置间距
combobox1 = ttk.Combobox(window, values=options1, width=20, height=10,name="性别选择")
combobox1.current(1) # 设置默认选中的选项
combobox1.pack(pady=10)
label = tk.Label(window, text="请输入您所要提问的问题:")
label.pack() # 添加标签并设置间距
entry = tk.Entry(window)
entry.pack(pady=20) # 垂直居中
button = tk.Button(window, text="提交", command=submit)
button.pack()
window.mainloop()
2、打包工具
pip install pyinstaller
pyinstaller --onefile script.py
--onefile
参数表示你想要一个独立的exe文件。
3、然后会在路径下生成一个dist文件夹
4、玩起来
输入你需要的
点击提交
ok,结束