Commit 57fcf99a authored by Jiabo Li's avatar Jiabo Li
Browse files

Updated local_gui with simpler design. Removed old files

parent b3201439
Loading
Loading
Loading
Loading

chatmol_lit.py

deleted100644 → 0
+0 −37
Original line number Diff line number Diff line
import requests
import json
from pymol import cmd

conversation_history = ""

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):
    global conversation_history
    question = conversation_history + 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_client.html

deleted100644 → 0
+0 −60
Original line number Diff line number Diff line
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Simple Form</title>
    <style>
        /* Add some basic styling */
        body {
            font-family: Arial, sans-serif;
            margin: 40px;
        }
        form {
            display: flex;
            flex-direction: column;
            width: 300px;
        }
        textarea {
            resize: none;
            height: 100px;
            margin-bottom: 10px;
        }
    </style>
</head>
<body>
    <form id="message-form">
        <label for="message">Your message to ChatGPT or PyMOL command directly to PyMOL:</label>
        <textarea id="message" name="message">chat fetch 1hiv and color red for chain A</textarea>
        <button type="submit">Send Message</button>
    </form>

    <script>
        // JavaScript code to handle form submission
        document.getElementById('message-form').addEventListener('submit', async (event) => {
            event.preventDefault(); // Prevent the form from submitting and refreshing the page

            const message = document.getElementById('message').value;
            const remoteServiceUrl = 'http://localhost:8000/send_message';

            try {
                const response = await fetch(remoteServiceUrl, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'text/plain'
                    },
                    body: message
                });

                if (response.ok) {
                    alert('Message sent successfully!');
                } else {
                    alert('Error: ' + response.statusText);
                }
            } catch (error) {
                alert('Error: ' + error.message);
            }
        });
    </script>
</body>
</html>

cm_client.py

deleted100644 → 0
+0 −15
Original line number Diff line number Diff line
import socket

def main():
    server_address = ('localhost', 8100)
    client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    client_socket.connect(server_address)

    message = input("Enter message to send to the server: ")
    client_socket.sendall(message.encode('utf-8'))
    client_socket.close()
    print("Message sent.")

if __name__ == '__main__':
    main()

cm_gui.py

deleted100644 → 0
+0 −41
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()

html/chatmol.html

deleted100644 → 0
+0 −86
Original line number Diff line number Diff line
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ChatMol + PyMOL</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
   <header>
        <nav>
            <ul>
                <li><a href="https://chatmol.org">ChatMol Home</a></li>
                <li><a href="https://github.com/JinyuanSun/ChatMol" target="_blank">ChatMol on Github</a></li>
                <li><a href="https://chatmol.org/screenshots.html">Screenshots</a></li>
                <li><a href="http://xp.chatmol.org/chatmol.html" target="_blank">PyMOL + ChatMol</a></li>
                <li><a href="https://chatmol.org/support.html">Support</a></li>
                <li><a href="https://chatmol.org/contact.html">Contact</a></li>
            </ul>
        </nav>
    </header>
    <div class="centered-text">
        <p>
This web form offers a conversational interface for interacting with PyMOL. You can send a message describing the tasks you wish to perform using PyMOL. To allow ChatMol to handle your requests, begin your message with the special keyword chat. Your task description can be as simple as "chat load 1hiv and color chain A in red and chain B in blue." Upon receiving this message, ChatMol will forward it to ChatGPT, process the response, extract a set of PyMOL commands along with their corresponding parameters, and execute these commands in sequence. Currently, ChatMol may take several seconds (sometimes more than 10 seconds) to respond due to the high demand for ChatGPT API calls. For straightforward PyMOL commands, you can bypass ChatGPT and send commands directly to PyMOL. To do this, simply omit the chat keyword and type the usual PyMOL commands, such as fetch 1hiv.
        </p>
    </div>
    <main class="sub-main">
        <div class="left-column">
            <div>
                <label for="sample-queries">Sample Queries:</label>
            </div>
            <div>
              <select id="sample-queries" size="10">
                <option>chat load 1hiv and color chain A in red and chain B in blue</option>
                <option>chat fetch 1OGA and color differetly for all chains in the protein</option>
                <!-- Add more sample queries as <option> elements -->
              </select>
            </div>
        </div>
        <div class="right-column">
          <form id="message-form">
            <div>
              <label for="message" style="width:143px">Message to PyMOL</label>
            </div>
            <div>
              <textarea id="message" name="message" rows="4">chat fetch 1hiv and color red for chain A and blue for chain B</textarea>
            </div>
            <div>
              <button type="submit">Send to Your PyMOL</button>
            </div>
         </form>
      </div>
    </main>
    <script>
        // JavaScript code to handle form submission
        document.getElementById('message-form').addEventListener('submit', async (event) => {
            event.preventDefault(); // Prevent the form from submitting and refreshing the page

            const message = document.getElementById('message').value;
            const remoteServiceUrl = 'http://localhost:8101/send_message';

            try {
                const response = await fetch(remoteServiceUrl, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'text/plain'
                    },
                    body: message
                });

                if (response.ok) {
                    alert('Message sent successfully!');
                } else {
                    alert('Error: ' + response.statusText);
                }
            } catch (error) {
                alert('Error: ' + error.message);
            }
        });
        document.getElementById('sample-queries').addEventListener('change', (event) => {
           const selectedQuery = event.target.value;
           document.getElementById('message').value = selectedQuery;
        });
    </script>
</body>
</html>
Loading