Spaces:
Sleeping
Sleeping
Commit ·
e33ca1b
1
Parent(s): 097033b
Initial version of chatbot
Browse files- .DS_Store +0 -0
- .gitattributes +1 -0
- app.py +105 -0
- assets/.DS_Store +0 -0
- assets/background_image/.DS_Store +0 -0
- assets/background_image/living_room.png +3 -0
- assets/chat_icons/person_icon.png +3 -0
- assets/chat_icons/robot_icon.png +3 -0
- requirements.txt +2 -0
.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import base64
|
| 3 |
+
import mimetypes
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
bg_path = "./assets/background_image/living_room.png"
|
| 7 |
+
with open(bg_path, "rb") as f:
|
| 8 |
+
bg_bytes = f.read()
|
| 9 |
+
bg_base64 = base64.b64encode(bg_bytes).decode("utf-8")
|
| 10 |
+
|
| 11 |
+
mime_type, _ = mimetypes.guess_type(bg_path)
|
| 12 |
+
if mime_type is None:
|
| 13 |
+
mime_type = "image/png"
|
| 14 |
+
|
| 15 |
+
BACKGROUND_CSS = f"""
|
| 16 |
+
.gradio-container {{
|
| 17 |
+
background-image: url("data:{mime_type};base64,{bg_base64}");
|
| 18 |
+
background-size: cover !important;
|
| 19 |
+
background-position: center !important;
|
| 20 |
+
max-width: 100% !important;
|
| 21 |
+
height: auto !important;
|
| 22 |
+
}}
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
GLASS_CSS = """
|
| 26 |
+
.glass {
|
| 27 |
+
background: rgba(255, 255, 255, 0.85) !important;
|
| 28 |
+
border-radius: 16px !important;
|
| 29 |
+
padding: 8px !important;
|
| 30 |
+
}
|
| 31 |
+
"""
|
| 32 |
+
|
| 33 |
+
USER_INPUT_CSS = """
|
| 34 |
+
#user-input textarea,
|
| 35 |
+
#user-input input {
|
| 36 |
+
border-radius: 999px !important;
|
| 37 |
+
border: 2px solid rgba(0, 0, 0, 0.15) !important;
|
| 38 |
+
padding: 0.6rem 1rem !important;
|
| 39 |
+
font-size: 0.95rem !important;
|
| 40 |
+
color: #222 !important;
|
| 41 |
+
outline: none !important;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
#user-input textarea:focus,
|
| 45 |
+
#user-input input:focus {
|
| 46 |
+
border-color: #4a7cf7 !important;
|
| 47 |
+
box-shadow: 0 0 0 2px rgba(74, 124, 247, 0.25) !important;
|
| 48 |
+
}
|
| 49 |
+
"""
|
| 50 |
+
|
| 51 |
+
CSS = BACKGROUND_CSS + \
|
| 52 |
+
"\n" + GLASS_CSS + \
|
| 53 |
+
"\n" + USER_INPUT_CSS
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def respond(message, history, name, job, age, city):
|
| 57 |
+
history = history or []
|
| 58 |
+
|
| 59 |
+
info = (
|
| 60 |
+
f"Name: {name or '-'}\n"
|
| 61 |
+
f"Beruf: {job or '-'}\n"
|
| 62 |
+
f"Alter: {age or '-'}\n"
|
| 63 |
+
f"Stadt: {city or '-'}"
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
bot_reply = f"Du hast geschrieben: '{message}'.\n\nDeine Angaben:\n{info}"
|
| 67 |
+
history.append((message, bot_reply))
|
| 68 |
+
return history, "", "", "", "", ""
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
with gr.Blocks(title="Form + Chat") as demo:
|
| 72 |
+
with gr.Row():
|
| 73 |
+
name = gr.Textbox(label="Name", elem_classes=["name-textbox"])
|
| 74 |
+
job = gr.Textbox(label="Beruf")
|
| 75 |
+
|
| 76 |
+
with gr.Row():
|
| 77 |
+
with gr.Column():
|
| 78 |
+
age = gr.Textbox(label="Alter")
|
| 79 |
+
city = gr.Textbox(label="Stadt")
|
| 80 |
+
|
| 81 |
+
with gr.Column():
|
| 82 |
+
chatbot = gr.Chatbot(
|
| 83 |
+
label="Chat",
|
| 84 |
+
avatar_images=(
|
| 85 |
+
"./assets/chat_icons/person_icon.png",
|
| 86 |
+
"./assets/chat_icons/robot_icon.png"
|
| 87 |
+
),
|
| 88 |
+
elem_classes=["glass"]
|
| 89 |
+
)
|
| 90 |
+
with gr.Row():
|
| 91 |
+
chat_input = gr.Textbox(
|
| 92 |
+
label="Nachricht",
|
| 93 |
+
elem_id="user-input"
|
| 94 |
+
)
|
| 95 |
+
submit = gr.Button(
|
| 96 |
+
"Submit",
|
| 97 |
+
elem_classes=["glass"])
|
| 98 |
+
|
| 99 |
+
submit.click(
|
| 100 |
+
fn=respond,
|
| 101 |
+
inputs=[chat_input, chatbot, name, job, age, city],
|
| 102 |
+
outputs=[chatbot, chat_input, name, job, age, city],
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
demo.launch(css=CSS)
|
assets/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
assets/background_image/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
assets/background_image/living_room.png
ADDED
|
Git LFS Details
|
assets/chat_icons/person_icon.png
ADDED
|
|
Git LFS Details
|
assets/chat_icons/robot_icon.png
ADDED
|
|
Git LFS Details
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==4.44.1
|
| 2 |
+
openai==2.8.1
|