I'm trying to make an AI chatbot using Android Studio which is supposed to use a Python core. I learnt how to run Python scripts in Android Studio using Chaquopy but when I run my .py
file which imports theaiml
library, there's always a "No match found for input" error. Here's my code for the file home.py which I'm running in Android Studio using Chaquopy:
import aiml
kernel = aiml.Kernel()
kernel.learn("std_startup.xml")
kernel.respond("load aiml b")
def response(message):
res = kernel.respond(message)
if res is None or res=="":
return "Sorry"
else:
return res
This is std_startup.xml
<aiml version="2.0" encoding="UTF-8">
<category>
<pattern>LOAD AIML B</pattern>
<template>
<learn>basic_chat.xml</learn>
</template>
</category>
</aiml>
This is basic_chat.xml
<aiml version="2.0" encoding="UTF-8">
<category>
<pattern>HELLO</pattern>
<template>
<random>
<li>Hey there!</li>
<li>H1!</li>
<li>Hello!</li>
</random>
</template>
</category>
</aiml>
The code in the Android project activity is:
if (!Python.isStarted()) {
Python.start(new AndroidPlatform(this));
}
Python python = Python.getInstance();
PyObject pythonFile = python.getModule("home");
PyObject response = pythonFile.callAttr("response", message.toString());
button.setText(response.toString());
All files are in the same directory. Chaquopy worked perfectly for simple python programs and home.py
worked fine when I was running it on cmd. I've tried changing the .xml
to .aiml
in the code but it still doesn't work. I also tried changing the aiml version.
What am I doing wrong? Or does Chaquopy just not support AIML? Please suggest any changes