maximiliandauner commited on
Commit
e33ca1b
·
1 Parent(s): 097033b

Initial version of chatbot

Browse files
.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

  • SHA256: 288321e27f915d48b875c700dc097e3eb34141d3d16ec51bebbba467eba3ebe4
  • Pointer size: 132 Bytes
  • Size of remote file: 1.52 MB
assets/chat_icons/person_icon.png ADDED

Git LFS Details

  • SHA256: 2b4aa57d37c1ab0f7b89ee36e54d209bb356371bc2ab7583256afe030fd9391a
  • Pointer size: 130 Bytes
  • Size of remote file: 14.8 kB
assets/chat_icons/robot_icon.png ADDED

Git LFS Details

  • SHA256: e6658e634e31ff2e7aa9e5b1b8200d6b1f7fb1bc5b0c08521a826b08541c4e49
  • Pointer size: 130 Bytes
  • Size of remote file: 19.7 kB
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio==4.44.1
2
+ openai==2.8.1