Exemple #1
0
class ElizaConsole:
    def __init__(self, config_file):
        self.HISTORY_FILENAME = os.path.expanduser('~/.eliza_history')
        self.init_history(self.HISTORY_FILENAME)
        self.eliza = Eliza(config_file)

    def run(self):
        print(self.eliza.initial())

        while True:
            try:
                sent = input('> ')
            except EOFError:
                break

            output = self.eliza.respond(sent)
            if output is None:
                break

            print(output)

        print(self.eliza.final())

    def init_history(self, histfile):
        readline.parse_and_bind("tab: complete")
        if hasattr(readline, "read_history_file"):
            try:
                readline.read_history_file(histfile)
            except IOError:
                pass
            atexit.register(self.save_history, histfile)

    def save_history(self, histfile):
        readline.set_history_length(1000)
        readline.write_history_file(histfile)
Exemple #2
0
def main():

    load_dotenv()
    token = os.getenv('DISCORD_TOKEN')
    channel = os.getenv('DISCORD_CHANNEL')

    bot = Eliza(token, channel)
    bot.run()
Exemple #3
0
 def __init__(self, name, avatar, sprite, scriptfile):
     self.name = name
     self.coordinates = (0,0)
     self.avatar = avatar
     self.sprite = sprite
     self.eliza = Eliza()
     #self.outputbox = OutputBox()
     #self.inputbox = InputBox()
     self.leadinfulfilled = False
     with open(scriptfile) as character_script:
         content = character_script.read()
         self.eliza.combined_script += content
Exemple #4
0
class Bee1(toga.App):
    def startup(self):
        #alternative icon embedding
        #path=os.path.dirname(os.path.abspath(__file__))
        #brutus_icon=os.path.join(path,"icons","brutus.icns")
        #Eliza module
        self.partner=Eliza()

        self.chat=toga.DetailedList(
            data=[
                {
                    'icon':toga.Icon('icons/ubs-logo.png'),

                    'title': 'Bot',
                    'subtitle': 'Hello. How are you feeling today?'
                }
            ]
            ,style=Pack(flex=1))

        self.text_input=toga.TextInput(style=Pack(flex=1))
        
        send_button=toga.Button('Send',style=Pack(padding_left=5),on_press=self.handle_input)

        input_box=toga.Box(
            children=[self.text_input, send_button],
            style=Pack(direction=ROW, alignment=CENTER, padding=5)
        )
#alignment='CENTER',
        # Create a main window with a name matching the app
        self.main_window = toga.MainWindow(title=self.name)

        # Create a main content box
        #main_box = toga.Box()

        # Add the content on the main window
        self.main_window.content = toga.Box(
            children=[self.chat,input_box],
            style=Pack(direction=COLUMN)
        )

        # Show the main window
        self.main_window.show()

    def handle_input(self,widget,**kwargs):
        input_text=self.text_input.value
        self.chat.data.append(
            icon=toga.Icon('icons/user2.png'),
            title='User',
            subtitle=input_text
        )
        self.text_input.value=''
        self.chat.scroll_to_bottom()

        yield random.random()*2        
        response=self.partner.respond(input_text)
        self.chat.data.append(
            icon=toga.Icon('icons/ubs-logo.png'),
            title='Bot',
            subtitle=response
        )
Exemple #5
0
class ElizaBot(BotPlugin):
    eliza_daemon = Eliza()

    @botcmd
    def eliza(self, _, args):
        """ El'cheapo shrink for you """
        args = args.strip()
        return self.eliza_daemon.respond(args)

    @botcmd
    def askus(self, _, __):
        """ Give us a fun topic to talk about
            thx to http://chatoms.com/
        """
        content = urlopen('http://chatoms.com/chatom.json?Normal=1&Fun=2&Philosophy=3&Out+There=4&Love=5&Personal=7').read()
        return json.loads(content.decode())['text']

    @botcmd
    def complete(self, _, args):
        """ Complete the given sentence
            thx to the awesome google completion
        """
        args = args.strip()
        if not args:
            return 'Complete what ?'

        content = urlopen('http://google.com/complete/search?q=%s&output=toolbar' % quote(args)).read()
        xml = objectify.fromstring(content)
        possibilities = xml.xpath("//toplevel/CompleteSuggestion/suggestion/@data")
        if possibilities:
            return choice(possibilities)
        return 'Hmmm... no answer for that'
Exemple #6
0
class Character:
    def __init__(self, name, avatar, sprite, scriptfile):
        self.name = name
        self.coordinates = (0,0)
        self.avatar = avatar
        self.sprite = sprite
        self.eliza = Eliza()
        #self.outputbox = OutputBox()
        #self.inputbox = InputBox()
        self.leadinfulfilled = False
        with open(scriptfile) as character_script:
            content = character_script.read()
            self.eliza.combined_script += content
    
    def load(self):
        self.eliza.load()

    def initiateDialogue(self, gameState):
        # Put main function of textbox here
        pass
Exemple #7
0
    def startup(self):
        #alternative icon embedding
        #path=os.path.dirname(os.path.abspath(__file__))
        #brutus_icon=os.path.join(path,"icons","brutus.icns")
        #Eliza module
        self.partner=Eliza()

        self.chat=toga.DetailedList(
            data=[
                {
                    'icon':toga.Icon('icons/ubs-logo.png'),

                    'title': 'Bot',
                    'subtitle': 'Hello. How are you feeling today?'
                }
            ]
            ,style=Pack(flex=1))

        self.text_input=toga.TextInput(style=Pack(flex=1))
        
        send_button=toga.Button('Send',style=Pack(padding_left=5),on_press=self.handle_input)

        input_box=toga.Box(
            children=[self.text_input, send_button],
            style=Pack(direction=ROW, alignment=CENTER, padding=5)
        )
#alignment='CENTER',
        # Create a main window with a name matching the app
        self.main_window = toga.MainWindow(title=self.name)

        # Create a main content box
        #main_box = toga.Box()

        # Add the content on the main window
        self.main_window.content = toga.Box(
            children=[self.chat,input_box],
            style=Pack(direction=COLUMN)
        )

        # Show the main window
        self.main_window.show()
Exemple #8
0
import random
from eliza import Eliza
from tools import connection, randomString
from flask import Flask
from flask import request
from flask import render_template
from flask import send_from_directory
from flask import session
from flask import make_response
from MySQLdb import escape_string as thwart
from datetime import datetime

# global vars
app = Flask(__name__, static_url_path="")
app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
therapist = Eliza();
success = json.dumps({"status": "OK"})
error = json.dumps({"status": "ERROR"})
cookies = dict()
histories = dict()  # holds the histories for each userid

# helper methods
def eliza_response(user_input):
    return '{"eliza": "' +  str(therapist.respond(user_input)) + ' "}'


# flask methods
@app.route('/eliza/static/<path:path>')
def send_static(path):
    return send_from_directory('static', path)
from eliza import Eliza

eliza = Eliza(lang='id')
print(eliza.respond('aku bosan'))
Exemple #10
0
from linebot.models import (
    MessageEvent, TextMessage, TextSendMessage, ImageSendMessage
)
from linebot.exceptions import (
    InvalidSignatureError
)
from linebot import (
    LineBotApi, WebhookHandler
)
import os
from flask import Flask, request, abort
from dotenv import load_dotenv
load_dotenv()


eliza = Eliza(lang='id')
app = Flask(__name__)

# get LINE_CHANNEL_ACCESS_TOKEN from your environment variable
line_bot_api = LineBotApi(os.environ.get('LINE_CHANNEL_ACCESS_TOKEN'))
# get LINE_CHANNEL_SECRET from your environment variable
handler = WebhookHandler(os.environ.get('LINE_CHANNEL_SECRET'))


@app.route("/")
def home():
    return "henlo world"


@app.route("/callback", methods=['POST'])
def callback():
Exemple #11
0
 def __init__(self, config_file):
     self.HISTORY_FILENAME = os.path.expanduser('~/.eliza_history')
     self.init_history(self.HISTORY_FILENAME)
     self.eliza = Eliza(config_file)
Exemple #12
0
#!/usr/bin/env python3
from eliza import Eliza

eliza = Eliza()
eliza.load('doctor-fr.txt')

print(eliza.initial())
while True:
    said = input('> ')
    response = eliza.respond(said)
    if response is None:
        break
    print(response)
print(eliza.final())