Unverified Commit cd92782a authored by Jiabo Li's avatar Jiabo Li Committed by GitHub
Browse files

Merge pull request #12 from JinyuanSun/add_lit

Add chatbot 
parents 25417b69 e18a42fb
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -136,7 +136,11 @@ def chat_with_gpt(message):
        print(f"Error: {e}")
        return ""

def start_chatgpt_cmd(message, execute:bool=True):
def start_chatgpt_cmd(message, execute:bool=True, lite:bool=True):
    if lite == True:
        from chatmol_lit import chatlit
        chatlit(message)
        return 0
    global stashed_commands
    global conversation_history

chatmol_lit.py

0 → 100644
+33 −0
Original line number Diff line number Diff line
import requests
import json
from pymol import cmd

def query_qaserver(question):
    headers = {
        'Content-Type': 'application/x-www-form-urlencoded',
    }

    data = 'question=' + question.replace('"','')

    response = requests.post('https://chatmol.org/qa/answer/', headers=headers, data=data)
    return response.text

def chatlit(question):
    answer = query_qaserver(question)
    data = json.loads(answer)
    commands = data['answer']
    commands = commands.split('\n')
    for command in commands:
        if command == '':
            continue
        else:
            cmd.do(command)
    print("Answers from ChatMol-QA: ")
    for command in commands:
        if command == '':
            continue
        else:
            print(command)


cmd.extend("chatlit", chatlit)
 No newline at end of file

cm_gui.py

0 → 100644
+41 −0
Original line number Diff line number Diff line
import tkinter as tk
from tkinter import messagebox
import socket

def send_message_to_pymol(message):
    remote_service_host = 'localhost'
    remote_service_port = 8100

    try:
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as client_socket:
            client_socket.connect((remote_service_host, remote_service_port))
            client_socket.sendall(message.encode('utf-8'))
            return 'Message sent successfully'
    except Exception as e:
        return f'Error: {e}'

def process_and_send():
    message = text_input.get()
    if not message:
        messagebox.showerror("Error", "Please enter a message")
        return

    # Call GPT here and get the response (as a command)
    command = message  # Replace this line with your actual GPT function call
    response = send_message_to_pymol(command)

    if "Error" in response:
        messagebox.showerror("Error", response)
    # else:
    #     messagebox.showinfo("Success", response)

app = tk.Tk()
app.title("GPT-3.5-turbo Chat")

text_input = tk.Entry(app, width=50)
text_input.pack()

send_button = tk.Button(app, text="Send Message", command=process_and_send)
send_button.pack()

app.mainloop()