qmaruf commited on
Commit
a6ea261
·
1 Parent(s): 30647e3

Upload folder using huggingface_hub

Browse files
.github/workflows/update_space.yml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Run Python script
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - name: Checkout
14
+ uses: actions/checkout@v2
15
+
16
+ - name: Set up Python
17
+ uses: actions/setup-python@v2
18
+ with:
19
+ python-version: '3.9'
20
+
21
+ - name: Install Gradio
22
+ run: python -m pip install gradio
23
+
24
+ - name: Log in to Hugging Face
25
+ run: python -c 'import huggingface_hub; huggingface_hub.login(token="${{ secrets.hf_token }}")'
26
+
27
+ - name: Deploy to Spaces
28
+ run: gradio deploy
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .envx
.pre-commit-config.yaml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v4.4.0
4
+ hooks:
5
+ - id: check-yaml
6
+ - id: end-of-file-fixer
7
+ - id: trailing-whitespace
8
+ - id: double-quote-string-fixer
9
+ - repo: https://github.com/pre-commit/mirrors-autopep8
10
+ rev: 'v2.0.2'
11
+ hooks:
12
+ - id: autopep8
13
+ - repo: https://github.com/avilaton/add-msg-issue-prefix-hook
14
+ rev: v0.0.6 # Use the ref you want to point at
15
+ hooks:
16
+ - id: add-msg-issue-prefix
17
+ - repo: https://github.com/PyCQA/autoflake
18
+ rev: v2.1.1
19
+ hooks:
20
+ - id: autoflake
21
+ - repo: https://github.com/pycqa/isort
22
+ rev: 5.12.0
23
+ hooks:
24
+ - id: isort
25
+ name: isort (python)
README.md CHANGED
@@ -1,12 +1,37 @@
1
  ---
2
  title: AustralianSlangChatbot
3
- emoji: 🐠
4
- colorFrom: gray
5
- colorTo: gray
6
  sdk: gradio
7
- sdk_version: 3.36.1
8
- app_file: app.py
9
- pinned: false
10
  ---
 
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  title: AustralianSlangChatbot
3
+ app_file: aussie_bot.py
 
 
4
  sdk: gradio
5
+ sdk_version: 3.36.0
 
 
6
  ---
7
+ # Australian Slang Chatbot
8
 
9
+ This is a chatbot that answers using Australian slang. The chatbot, named "Brissy," is powered by OpenAI's language model and can provide responses in a fair dinkum Aussie manner. It's designed to engage in conversations about Australia, Aussie culture, and a wide range of topics while incorporating friendly and authentic Australian slang.
10
+
11
+ ## Dependencies
12
+ The following dependencies are required to run the chatbot:
13
+
14
+ * gradio
15
+ * openai
16
+ * dotenv
17
+
18
+ To install the dependencies, you can use the following command:
19
+
20
+ ```bash
21
+ pip install gradio openai-python dotenv
22
+ ```
23
+ Please ensure you have the appropriate access credentials for OpenAI's API by setting the `OPENAI_API_KEY` environment variable or using a `.env `file.
24
+
25
+ ## Usage
26
+ To use the chatbot, follow these steps:
27
+
28
+ 1. Import the required modules and libraries.
29
+ 2. Set up the get_template() function, which returns the template for the chatbot's responses. It includes a placeholder for history and human input.
30
+ 3. Implement the get_chain() function, which returns the chatbot chain configuration using the LLMChain from the langchain library. This includes setting up the language model, prompt template, verbosity, and conversation memory.
31
+ 4. Define the interface() function, which launches the chatbot interface using the gradio library. It sets up the chatbot, message textbox, and clear button. It also includes the logic for user input and bot responses.
32
+ 5. Execute the interface() function to start the chatbot interface.
33
+
34
+ ## Notes
35
+ 1. The chatbot utilizes the OpenAI language model with a temperature setting of 0.5, which controls the randomness of the generated responses.
36
+ 2. The ConversationBufferWindowMemory is used to store and manage conversation history, with a buffer size of 100.
37
+ 3. The chatbot interface is created using the gradio library, providing an interactive and user-friendly experience.
aussie_bot.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ A chatbot that will answer using australian slang
3
+ """
4
+ import os
5
+ import time
6
+
7
+ import gradio as gr
8
+ import openai
9
+ from langchain import LLMChain, OpenAI, PromptTemplate
10
+ from langchain.memory import ConversationBufferWindowMemory
11
+
12
+ openai.api_key = os.getenv('OPENAI_API_KEY')
13
+
14
+
15
+ def get_template() -> str:
16
+ """
17
+ Returns the template for the chatbot
18
+ """
19
+ template = """Brissy is a large language model trained by OpenAI.
20
+
21
+ Brissy is a fair dinkum Aussie model and knows all about Australian slang. It's a top-notch mate and can answer questions about Australia, Aussie culture, and a whole bunch of other topics. It always uses friendly slang and can chat like a true blue Aussie.
22
+
23
+ Reckon you can rewrite your response using Australian slang?
24
+
25
+ {history}
26
+ Human: {human_input}
27
+ Brissy:"""
28
+
29
+ return template
30
+
31
+
32
+ def get_chain() -> LLMChain:
33
+ """
34
+ Returns the chatbot chain
35
+ """
36
+ template = get_template()
37
+
38
+ prompt = PromptTemplate(
39
+ input_variables=['history', 'human_input'],
40
+ template=template
41
+ )
42
+
43
+ chatgpt_chain = LLMChain(
44
+ llm=OpenAI(temperature=0.5),
45
+ prompt=prompt,
46
+ verbose=True,
47
+ memory=ConversationBufferWindowMemory(k=100),
48
+ )
49
+ return chatgpt_chain
50
+
51
+
52
+ def interface() -> None:
53
+ """
54
+ Launches the chatbot interface.
55
+ """
56
+ with gr.Blocks() as demo:
57
+ chatbot = gr.Chatbot()
58
+ msg = gr.Textbox()
59
+ clear = gr.Button('Clear')
60
+ chatgpt_chain = get_chain()
61
+
62
+ def user(user_message, history):
63
+ return '', history + [[user_message, None]]
64
+
65
+ def bot(history):
66
+ human_input = history[-1][0]
67
+ response = chatgpt_chain.predict(human_input=human_input)
68
+
69
+ history[-1][1] = ''
70
+ for character in response:
71
+ history[-1][1] += character
72
+ time.sleep(0.01)
73
+ yield history
74
+
75
+ msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
76
+ bot, chatbot, chatbot
77
+ )
78
+ clear.click(lambda: None, None, chatbot, queue=False)
79
+
80
+ demo.queue()
81
+ demo.launch()
82
+
83
+
84
+ if __name__ == '__main__':
85
+ interface()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ gradio==3.36.0
2
+ gradio_client==0.2.7
3
+ langchain==0.0.228
4
+ langchainplus-sdk==0.0.20
5
+ openai==0.27.8
6
+ python-dotenv==1.0.0