Commit ec800513 authored by JinyuanSun's avatar JinyuanSun
Browse files

add chatmol-lit

parent c9d2abc1
Loading
Loading
Loading
Loading

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