gunthercox / ChatterBot

ChatterBot is a machine learning, conversational dialog engine for creating chat bots
https://chatterbot.readthedocs.io
BSD 3-Clause "New" or "Revised" License
14.08k stars 4.44k forks source link

[Errno30] Chatterbot on Android Device throws exception #1973

Closed Amira-Ali closed 4 years ago

Amira-Ali commented 4 years ago

Hello Sir,

I'm trying to get chatterbot to work on android device using (Chaquopy) and android studio of course, I'm getting this error:

[Errno30] Read-only file system: 'sentence_tokenizer.pickle'

I guess it's caused by line no.31 in python script: response = Bot.get_response(input_statement)

If I run the same python script with PyCharm on windows, it works like a charm. Maybe it's not chatterbot related issue, maybe it's a user permission problem (I've set android studio app premission to read and write in the AndroidManifest), maybe it's a Chaquopy problem or maybe I'm a really bad programmer, I don't know.

I really appreciate any help, I'm desperate here..

Thank you

buildgradle: apply plugin: 'com.android.application' apply plugin: 'com.chaquo.python'

android { compileSdkVersion 29 buildToolsVersion "29.0.3"

defaultConfig { applicationId "com.example.pythontest2" sourceSets { main { python { srcDirs = ["src/main/python"] } } } minSdkVersion 16 targetSdkVersion 29 versionCode 1 versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
    abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
}
python {
    buildPython "C:/Users/ashlibek/AppData/Local/Programs/Python/Python38/python.exe"

    pip {
        install "six==1.14.0"
        install "nltk==3.4.5"
        install "SQLAlchemy==1.2.19"
        install "PyYAML==3.13"
        install "pytz==2019.3"
        install "python-dateutil==2.7.5"
        install "mathparse==0.1.2"
        install "thinc"
        install "blis"
        install "spacy"
        install "chatterbot==1.0.5"
        install "chatterbot_corpus==1.2.0"

    }
}

}

buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } }

dependencies { implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'com.google.android.material:material:1.1.0' implementation 'androidx.annotation:annotation:1.1.0' implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' implementation 'androidx.navigation:navigation-fragment:2.2.2' implementation 'androidx.navigation:navigation-ui:2.2.2' implementation 'androidx.vectordrawable:vectordrawable:1.1.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' implementation 'androidx.recyclerview:recyclerview:1.1.0' implementation "androidx.constraintlayout:constraintlayout:2.0.0-beta5" }

Python Script: from chatterbot import ChatBot from chatterbot import comparisons from chatterbot.conversation import Statement from chatterbot.response_selection import get_most_frequent_response

uri='sqlite:///data/data/com.example.pythontest2/files/BotData.sqlite3'

Bot = ChatBot( 'Dr. Lito', storage_adapter='chatterbot.storage.SQLStorageAdapter', database_uri=uri, logic_adapters=[ { "import_path": "chatterbot.logic.BestMatch", "statement_comparison_function": "comparisons.levenshtein_distance", "response_selection_method": get_most_frequent_response, "default_response": "I am sorry, but I do not understand.", "maximum_similarity_threshold": 0.90 } ] )

def start_bot(): return "Hi"

def start_chat(userentry): try: input_statement = Statement(text=userentry) response = Bot.get_response(input_statement) except Exception as e: return 'Error: ' + str(e) return response.text

Amira-Ali commented 4 years ago

Thanks to @mhsmith it works now, the solution is here:

https://github.com/chaquo/chaquopy/issues/280

Thank you