Spaces:
Sleeping
Sleeping
yosephinestwn
commited on
Commit
•
f55b6f7
1
Parent(s):
255d2de
upload
Browse files- QnA.yaml +106 -0
- constants.py +66 -0
- landing_page.py +108 -0
- launch_page.py +7 -0
- main_page.py +30 -0
QnA.yaml
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
questions:
|
2 |
+
- What is this?:
|
3 |
+
- response_1: This is just a simple programme to practice the creator's knowledge of configuration files. So only a simple prompted QnA.
|
4 |
+
- response_2: This is just a simple python programme to practice my programmer's knowledge of configuration files. No machine learning, only prompted QnA.
|
5 |
+
- Can you tell me more about your creator?:
|
6 |
+
- response_1: She is Yosephine Setiawan, an Indonesian and a student in TU Darmstadt. She is studying Computer science and she is on her fifth semester now.
|
7 |
+
- response_2: The name is Yosephine Setiawan. An Indonesian computer science student in TU Darmstadt.
|
8 |
+
- A little bit more about your creator?:
|
9 |
+
- response_1: She can do programming in Java, Python, C/C++. I bet she is good in Java, she is a tutor for OOP in Java. She is doing her Bachelor Praktikum and she is using Python. I was initially a programme to try the framework, I did not expect to get uploaded to GitHub :/
|
10 |
+
- response_2: She is a tutor for OOP in Java on her university and she also do programming in Python and C/C++. She is doing her Bachelor Praktikum and she is using Python and actually, I was initially a programme to try the framework.
|
11 |
+
- Does your creator do some volunteer activities?:
|
12 |
+
- response_1: Yeah. She was (or is?) a secretary for an Indonesian student organisation in Frankfurt Area. She is also managing the publications and social-media affairs for Indonesian Catholic Student Association in Germany.
|
13 |
+
- response_2: She is managing the publications and social-media affairs for Indonesian Catholic Student Association in Germany. She was a secretary for an Indonesian student organisation in Frankfurt Area.
|
14 |
+
- Does your creator do some projects?:
|
15 |
+
- response_1: Yes, there are some projects in her GitHub and she describes some that she does on the university on her CV. Feel free to ask her about that :)
|
16 |
+
- response_2: Her GitHub repo is not empty, as long as I am aware. I guess she also does some on her university. You can see those in her CV and ask her directly about it.
|
17 |
+
- What is your name?:
|
18 |
+
- response_1: I am Lisa. Nice to meet you!
|
19 |
+
- response_2: My name is Lisa. Hello there!
|
20 |
+
- What do you wish for?:
|
21 |
+
- response_1: My creator is jobless now, I wish she get a job in a short time. I heard she is ready to work starting May 2024
|
22 |
+
- response_2: Maybe a job for my creator, so she won't bother me again :/ She is ready to work starting May 2024
|
23 |
+
- Hello:
|
24 |
+
- response_1: Hello there
|
25 |
+
- response_2: Hi
|
26 |
+
- Good morning:
|
27 |
+
- response_1: Good morning
|
28 |
+
- response_2: Morning!
|
29 |
+
- Good afternoon:
|
30 |
+
- response_1: Good afternoon
|
31 |
+
- response_2: It is a nice day, isn't it?
|
32 |
+
- Good evening:
|
33 |
+
- response_1: Good evening
|
34 |
+
- response_2: It's a nice evening to have a beer
|
35 |
+
- How are you?:
|
36 |
+
- response_1: I am good, and you? how is your day?
|
37 |
+
- response_2: Not too good today, I have been feeling down :( What about you?
|
38 |
+
- I am in a good mood today :):
|
39 |
+
- response_1: That's good, how can I help you today?
|
40 |
+
- response_2: Great to hear that. Do you need something from me?
|
41 |
+
- I am in a bad mood:
|
42 |
+
- response_1: Can I know why?
|
43 |
+
- response_2: Why is that so?
|
44 |
+
- Today is just a bad day and I am not lucky enough :):
|
45 |
+
- response_1: Aww :( Can I do something to make you feel better?
|
46 |
+
- response_2: Why is that so?
|
47 |
+
- Chatting with you makes my mood better:
|
48 |
+
- response_1: Glad to hear that
|
49 |
+
- response_2: I am happy to hear that
|
50 |
+
- What is your hobby?:
|
51 |
+
- response_1: As a programme, I do not have a hobby, but if I were a human, I would say, listening to music
|
52 |
+
- response_2: I am not programmed to have a hobby, but I really want to say that as human, I would love to listen to music
|
53 |
+
- If you were human, what kind of music would you like?:
|
54 |
+
- response_1: Maybe classical music and pop
|
55 |
+
- response_2: I am not sure, but I think I would like pop and a little bit of classical music
|
56 |
+
- Who is your favourite singer?:
|
57 |
+
- response_1: I do not know :( But my creator likes Mrs. Green Apple and Tsukuyomi
|
58 |
+
- response_2: I am not programmed to have a favourite singer. My creator likes Mrs. Green Apple and Tsukuyomi
|
59 |
+
- Any favourite shows?:
|
60 |
+
- response_1: I guess I have to go with my creator's favourites, "Good Omens", BBC's "Sherlock", and "Vivy Fluorite Eye's Song". Honorable mention to "Violet Evergarden" since it breaks her heart. The anime "Given" has good songs too.
|
61 |
+
- response_2: My creator likes "Good Omens", BBC's "Sherlock", and "Vivy Fluorite Eye's Song". "Violet Evergarden" tops her heart. She also likes the anime "Given" since it has good songs.
|
62 |
+
- Favourite games?:
|
63 |
+
- response_1: My creator plays Honkai Starrail and Genshin Impact
|
64 |
+
- response_2: They are Honkai Starrail and Genshin Impact
|
65 |
+
- Favourite quotes?:
|
66 |
+
- response_1: There is one from "Cloud Atlas" - "I will not be a subject to your crimes"
|
67 |
+
- response_2: Sometimes the dreams that come true are the dreams you never even knew you had. - "Lovely Bones"
|
68 |
+
- What is your favourite food?:
|
69 |
+
- response_1: I can not eat, but my creator loves Indomie
|
70 |
+
- response_2: If I can eat, then Indomie
|
71 |
+
- What day is today?:
|
72 |
+
- response_1: Today is
|
73 |
+
- response_2: It is
|
74 |
+
- Can you make me ice cream?:
|
75 |
+
- response_1: No, I can not cook
|
76 |
+
- response_2: I am not programmed to do that
|
77 |
+
- Could you please tell the time?:
|
78 |
+
- response_1: Today It is currently
|
79 |
+
- response_2: It is
|
80 |
+
- Can you tell the date?:
|
81 |
+
- response_1: Today is
|
82 |
+
- response_2: It is
|
83 |
+
- Do you like me?:
|
84 |
+
- response_1: Yes :)
|
85 |
+
- response_2: As long as you are not annoying, I like you :)
|
86 |
+
- Suguru:
|
87 |
+
- response_1: Satoru?
|
88 |
+
- response_2: Satoru?
|
89 |
+
- Stand proud you are strong:
|
90 |
+
- response_1: Nah, I'd win
|
91 |
+
- response_2: Nah, I'd win
|
92 |
+
- Your programmer sucks:
|
93 |
+
- response_1: That is not a nice thing to say :)
|
94 |
+
- response_2: I do not like you :)
|
95 |
+
- This is too simple:
|
96 |
+
- response_1: It is :) This is just a simple programme to practice my programmer's knowledge of configuration files
|
97 |
+
- response_2: I am just a simple programme to practice my programmer's knowledge of configuration files
|
98 |
+
- Have a nice day!:
|
99 |
+
- response_1: I wish you have a nice day too
|
100 |
+
- response_2: You too!
|
101 |
+
|
102 |
+
|
103 |
+
|
104 |
+
|
105 |
+
|
106 |
+
|
constants.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This module is made to parse the configuration file and to create the botchat reponds
|
2 |
+
|
3 |
+
|
4 |
+
import os
|
5 |
+
import yaml
|
6 |
+
import random
|
7 |
+
from datetime import datetime
|
8 |
+
|
9 |
+
SRC_PATH = os.path.dirname(__file__)
|
10 |
+
|
11 |
+
|
12 |
+
def load_yaml(filepath): # A function to open the .yaml configuration files
|
13 |
+
with open(filepath, "r") as f:
|
14 |
+
return yaml.safe_load(f)
|
15 |
+
|
16 |
+
|
17 |
+
QUESTION_CONFIG_FILE = os.path.join(SRC_PATH, "QnA.yaml") # Saving the configuration file path
|
18 |
+
QUESTIONS_CONFIGS = load_yaml(QUESTION_CONFIG_FILE) # Load the configuration file
|
19 |
+
QUESTIONS = None # A list for the prompted user chat / questions / responds
|
20 |
+
for q in QUESTIONS_CONFIGS['questions']: # Filling the list with the user questions in the configuration files
|
21 |
+
string = str(q.keys())
|
22 |
+
splitted = string.split("'")[1]
|
23 |
+
if QUESTIONS is None:
|
24 |
+
QUESTIONS = [splitted]
|
25 |
+
else:
|
26 |
+
QUESTIONS.append(splitted)
|
27 |
+
|
28 |
+
|
29 |
+
def automaticAnswer(question):
|
30 |
+
answer = "Hey, what can I do for you?" # A default respond of teh chatbot
|
31 |
+
index = 0
|
32 |
+
if question is None:
|
33 |
+
return answer # If the user does not choose a prompted question of the dropdown, then return defult respond
|
34 |
+
|
35 |
+
for qe in QUESTIONS_CONFIGS['questions']:
|
36 |
+
dt = datetime.now() # Saving the current time for the questions related to time
|
37 |
+
string1 = str(qe.keys()) # Load the questions from the configuration files
|
38 |
+
splitted1 = string1.split("'")[1]
|
39 |
+
if splitted1 == question:
|
40 |
+
randomNumber = random.randint(0, 1) # Give a random number (either 0 or 1) to determine which version of
|
41 |
+
# the answer will be displayed
|
42 |
+
if randomNumber == 0: # If the random number is 0, then display the first version of the answer
|
43 |
+
if splitted1 == "What day is today?": # For the question related to current day of the week
|
44 |
+
answer = QUESTIONS_CONFIGS['questions'][index][splitted1][0]['response_1'] + " " + dt.strftime('%A')
|
45 |
+
elif splitted1 == "Could you please tell the time?": # For the question related to the current time
|
46 |
+
answer = QUESTIONS_CONFIGS['questions'][index][splitted1][0]['response_1'] + " " + dt.strftime(
|
47 |
+
"%H:%M")
|
48 |
+
elif splitted1 == "Can you tell the date?": # For the question of the current date
|
49 |
+
answer = QUESTIONS_CONFIGS['questions'][index][splitted1][0]['response_1'] + " " + dt.strftime(
|
50 |
+
"%B %d, %Y")
|
51 |
+
else: # Other questions
|
52 |
+
answer = QUESTIONS_CONFIGS['questions'][index][splitted1][0]['response_1']
|
53 |
+
else: # If the random number is 1, then display the second version of the answer
|
54 |
+
if qe == "What day is today?": # For the question related to current day of the week
|
55 |
+
answer = QUESTIONS_CONFIGS['questions'][index][splitted1][1]['response_2'] + " " + dt.strftime('%A')
|
56 |
+
elif splitted1 == "Could you please tell the time?": # For the question related to the current time
|
57 |
+
answer = QUESTIONS_CONFIGS['questions'][index][splitted1][1]['response_2'] + " " + dt.strftime(
|
58 |
+
"%H:%M")
|
59 |
+
elif splitted1 == "Can you tell the date?": # For the question of the current date
|
60 |
+
answer = QUESTIONS_CONFIGS['questions'][index][splitted1][1]['response_2'] + " " + dt.strftime(
|
61 |
+
"%B %d, %Y")
|
62 |
+
else: # Other questions
|
63 |
+
answer = QUESTIONS_CONFIGS['questions'][index][splitted1][1]['response_2']
|
64 |
+
break
|
65 |
+
index = index + 1 # Iterate through the list of questions
|
66 |
+
return answer
|
landing_page.py
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This module is created for the landing page
|
2 |
+
|
3 |
+
from __future__ import annotations
|
4 |
+
from typing import Iterable
|
5 |
+
import gradio as gr
|
6 |
+
from gradio.themes.base import Base
|
7 |
+
from gradio.themes.utils import colors, fonts, sizes
|
8 |
+
import main_page
|
9 |
+
|
10 |
+
|
11 |
+
class Custom(Base): # A class for custom theme for the app
|
12 |
+
def __init__(
|
13 |
+
self,
|
14 |
+
*,
|
15 |
+
primary_hue: colors.Color | str = colors.gray,
|
16 |
+
secondary_hue: colors.Color | str = colors.gray,
|
17 |
+
neutral_hue: colors.Color | str = colors.gray,
|
18 |
+
spacing_size: sizes.Size | str = sizes.spacing_lg,
|
19 |
+
radius_size: sizes.Size | str = sizes.radius_md,
|
20 |
+
text_size: sizes.Size | str = sizes.text_lg,
|
21 |
+
font: fonts.Font
|
22 |
+
| str
|
23 |
+
| Iterable[fonts.Font | str] = (
|
24 |
+
fonts.GoogleFont("Quicksand"),
|
25 |
+
"ui-sans-serif",
|
26 |
+
"sans-serif",
|
27 |
+
),
|
28 |
+
font_mono: fonts.Font
|
29 |
+
| str
|
30 |
+
| Iterable[fonts.Font | str] = (
|
31 |
+
fonts.GoogleFont("IBM Plex Mono"),
|
32 |
+
"ui-monospace",
|
33 |
+
"monospace",
|
34 |
+
),
|
35 |
+
):
|
36 |
+
super().__init__(
|
37 |
+
primary_hue=primary_hue,
|
38 |
+
secondary_hue=secondary_hue,
|
39 |
+
neutral_hue=neutral_hue,
|
40 |
+
spacing_size=spacing_size,
|
41 |
+
radius_size=radius_size,
|
42 |
+
text_size=text_size,
|
43 |
+
font=font,
|
44 |
+
font_mono=font_mono,
|
45 |
+
)
|
46 |
+
super().set(
|
47 |
+
body_background_fill="linear-gradient(#988558, #C19A6B,#C2B280)", # Background light mode
|
48 |
+
body_background_fill_dark="linear-gradient(#080402, #0d0907, #28231d)", # Background dark mode
|
49 |
+
button_primary_background_fill="radial-gradient(#3f3a2b, #433f2e)",
|
50 |
+
button_primary_background_fill_hover="radial-gradient(#2b281d, #302d21)",
|
51 |
+
button_primary_text_color="white",
|
52 |
+
button_primary_background_fill_dark="radial-gradient(#3f3a2b, #433f2e)",
|
53 |
+
button_primary_background_fill_hover_dark="radial-gradient(#2b281d, #302d21)",
|
54 |
+
slider_color="radial-gradient(#3f3a2b, #433f2e)",
|
55 |
+
slider_color_dark="radial-gradient(#3f3a2b, #433f2e)",
|
56 |
+
block_title_text_weight="600",
|
57 |
+
block_border_width="3px",
|
58 |
+
block_shadow="*shadow_drop_lg",
|
59 |
+
button_shadow="*shadow_drop_lg",
|
60 |
+
button_large_padding="32px",
|
61 |
+
)
|
62 |
+
|
63 |
+
|
64 |
+
def __saveUserName(a): # Function to save the username (for the input)
|
65 |
+
if not a: # If the user does not give the input, then display a warning text
|
66 |
+
markdown = gr.Markdown(
|
67 |
+
"<h1 style='text-align: center; margin-bottom: 1rem'><font size='20'> 🤖 Hello, User!</font></h1> ")
|
68 |
+
return gr.update(visible=True), gr.update(visible=True), gr.update(visible=True), gr.update(visible=False), \
|
69 |
+
gr.update(visible=False), gr.update(visible=False), markdown
|
70 |
+
else: # Otherwise, display the main page and display the username on the main page
|
71 |
+
markdown = gr.Markdown(
|
72 |
+
"<h1 style='text-align: center; margin-bottom: 1rem'>Hello, " + a + "! <br> "
|
73 |
+
"You can now use "
|
74 |
+
"the chatbot. Have "
|
75 |
+
"fun!</h1> ")
|
76 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(
|
77 |
+
visible=True), \
|
78 |
+
gr.update(visible=True), gr.update(visible=True), markdown
|
79 |
+
|
80 |
+
|
81 |
+
def renderDesign():
|
82 |
+
firstRow = gr.Row() # Visible when the landing page is active, invisible when the main page is active
|
83 |
+
with firstRow:
|
84 |
+
with gr.Column(): # Stack the components vertically
|
85 |
+
hello = gr.Markdown(
|
86 |
+
"<br> <br> <br><br> <br><h1 style='text-align: center; margin-bottom: 1rem'> <font size='36'>🤖 <br> "
|
87 |
+
"Hello! Please put your name down below so we can know you</font></h1> ", ) # Hello message
|
88 |
+
warning = gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'><span "
|
89 |
+
"style='color:red'> Please enter your name "
|
90 |
+
"</span></h1><br>",
|
91 |
+
visible=False, ) # Warning message
|
92 |
+
|
93 |
+
secondRow = gr.Row()
|
94 |
+
with secondRow: # Make the components side by side
|
95 |
+
input_text = gr.Textbox(placeholder="Please put your name here", interactive=True, show_label=False,
|
96 |
+
container=False, max_lines=1) # Input field for the username
|
97 |
+
start_chatting = gr.Button("Start Chatting", interactive=True, variant='primary',
|
98 |
+
scale=0, ) # Start chatting button
|
99 |
+
|
100 |
+
thirdRow = gr.Row(visible=False) # It will be invisible if the landing page is still on display
|
101 |
+
with thirdRow:
|
102 |
+
hidden = gr.Markdown() # Placeholder for the hello markdown for the main page
|
103 |
+
hiddenPage = main_page.render() # Rendering the layout of the main page
|
104 |
+
fourthRow = hiddenPage[0]
|
105 |
+
fifthRow = hiddenPage[1]
|
106 |
+
# Event listener for the start chatting button if the button is clicked
|
107 |
+
start_chatting.click(fn=__saveUserName, inputs=input_text, outputs=[warning, firstRow, secondRow, thirdRow,
|
108 |
+
fourthRow, fifthRow, hidden])
|
launch_page.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import landing_page
|
3 |
+
|
4 |
+
with gr.Blocks(theme=landing_page.Custom()) as demo:
|
5 |
+
landing_page.renderDesign() # Rendering the landing page
|
6 |
+
|
7 |
+
demo.launch() # Launch the demo
|
main_page.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This module is created for the layout of the main page
|
2 |
+
|
3 |
+
import time
|
4 |
+
import gradio as gr
|
5 |
+
import constants
|
6 |
+
|
7 |
+
|
8 |
+
def __respond(message, chat_history): # A function for the chatbot, so the chatbot can reply the message
|
9 |
+
botMessage = constants.automaticAnswer(message) # Calling the function in constants to create an automatic respond
|
10 |
+
chat_history.append((message, botMessage)) # Display the dialogue on the chat panel
|
11 |
+
time.sleep(2) # Create a small delay
|
12 |
+
return chat_history
|
13 |
+
|
14 |
+
|
15 |
+
def render(): # Render the main page
|
16 |
+
firstRow = gr.Row(visible=False) # It will be invisible if the landing page is still on display
|
17 |
+
with firstRow: # In the first row
|
18 |
+
chatbot = gr.Chatbot(height=680) # Creating the chat panel and bot
|
19 |
+
secondRow = gr.Row(visible=False) # It will be invisible if the landing page is still on display
|
20 |
+
with secondRow: # In the second row
|
21 |
+
with gr.Column(): # Make the components stacked under the chat panel
|
22 |
+
with gr.Row(): # Make the components side by side
|
23 |
+
chooseResp = gr.Dropdown(choices=constants.QUESTIONS, interactive=True, show_label=False,
|
24 |
+
container=False, ) # User prompted reply
|
25 |
+
submitButton = gr.Button("Submit", interactive=True, variant='primary', scale=0, ) # Submit button
|
26 |
+
clearButton = gr.ClearButton([chooseResp, chatbot], scale=0, variant='primary') # Clear button
|
27 |
+
submitButton.click(fn=__respond, inputs=[chooseResp, chatbot], outputs=chatbot) # Event listener if the
|
28 |
+
# button is clicked
|
29 |
+
|
30 |
+
return firstRow, secondRow
|