File size: 5,842 Bytes
98b5314
7f93957
 
b47f6e6
7f93957
7dde4c4
7f93957
 
 
 
b47f6e6
 
 
 
7f93957
 
 
 
 
 
 
 
7ab8364
4516d66
 
 
 
 
 
 
 
 
 
 
 
 
 
9869d32
752ff58
 
9869d32
4516d66
 
 
 
19d4a49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
afc99ad
4516d66
 
 
 
9869d32
4516d66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7ab8364
98b5314
7f93957
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import time
import random
import gradio as gr
# from transformers import pipeline

# p = pipeline("automatic-speech-recognition")

def user(user_message, history):
    return "", history + [[user_message, None]]

# def transcribe(audio, state=""):
#     text = p(audio)["text"]
#     state += text + " "
#     return state, state

def bot(history):
    bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
    history[-1][1] = ""
    for character in bot_message:
        history[-1][1] += character
        time.sleep(0.05)
        yield history

css = """
        .gradio-container {
            font-family: 'IBM Plex Sans', sans-serif;
        }
        .gr-button {
            color: white;
            border-color: black;
            background: black;
        }
        .container {
            max-width: 730px;
            margin: auto;
            padding-top: 1.5rem;
        }
        #chatbot {
            min-height: 30rem;
            margin: auto;
        }
"""

with gr.Blocks(css=css) as demo:

    # gr.HTML(
    #     """
    #         <div style="text-align: center; margin: 0 auto;">
    #           <div
    #             style="
    #               display: inline-flex;
    #               align-items: center;
    #               gap: 0.8rem;
    #               font-size: 1.75rem;
    #             "
    #           >
    #             <svg
    #               width="0.65em"
    #               height="0.65em"
    #               viewBox="0 0 115 115"
    #               fill="none"
    #               xmlns="http://www.w3.org/2000/svg"
    #             >
    #               <rect width="23" height="23" fill="white"></rect>
    #               <rect y="69" width="23" height="23" fill="white"></rect>
    #               <rect x="23" width="23" height="23" fill="#AEAEAE"></rect>
    #               <rect x="23" y="69" width="23" height="23" fill="#AEAEAE"></rect>
    #               <rect x="46" width="23" height="23" fill="white"></rect>
    #               <rect x="46" y="69" width="23" height="23" fill="white"></rect>
    #               <rect x="69" width="23" height="23" fill="black"></rect>
    #               <rect x="69" y="69" width="23" height="23" fill="black"></rect>
    #               <rect x="92" width="23" height="23" fill="#D9D9D9"></rect>
    #               <rect x="92" y="69" width="23" height="23" fill="#AEAEAE"></rect>
    #               <rect x="115" y="46" width="23" height="23" fill="white"></rect>
    #               <rect x="115" y="115" width="23" height="23" fill="white"></rect>
    #               <rect x="115" y="69" width="23" height="23" fill="#D9D9D9"></rect>
    #               <rect x="92" y="46" width="23" height="23" fill="#AEAEAE"></rect>
    #               <rect x="92" y="115" width="23" height="23" fill="#AEAEAE"></rect>
    #               <rect x="92" y="69" width="23" height="23" fill="white"></rect>
    #               <rect x="69" y="46" width="23" height="23" fill="white"></rect>
    #               <rect x="69" y="115" width="23" height="23" fill="white"></rect>
    #               <rect x="69" y="69" width="23" height="23" fill="#D9D9D9"></rect>
    #               <rect x="46" y="46" width="23" height="23" fill="black"></rect>
    #               <rect x="46" y="115" width="23" height="23" fill="black"></rect>
    #               <rect x="46" y="69" width="23" height="23" fill="black"></rect>
    #               <rect x="23" y="46" width="23" height="23" fill="#D9D9D9"></rect>
    #               <rect x="23" y="115" width="23" height="23" fill="#AEAEAE"></rect>
    #               <rect x="23" y="69" width="23" height="23" fill="black"></rect>
    #             </svg>
    #             <h1 style="font-weight: 900; margin-bottom: 7px;margin-top:5px">
    #               Stable Diffusion 2.1 Demo
    #             </h1>
    #           </div>
    #           <p style="margin-bottom: 10px; font-size: 94%; line-height: 23px;">
    #             Stable Diffusion 2.1 is the latest text-to-image model from StabilityAI. <a style="text-decoration: underline;" href="https://huggingface.co/spaces/stabilityai/stable-diffusion-1">Access Stable Diffusion 1 Space here</a><br>For faster generation and API
    #             access you can try
    #             <a
    #               href="http://beta.dreamstudio.ai/"
    #               style="text-decoration: underline;"
    #               target="_blank"
    #               >DreamStudio Beta</a
    #             >.</a>
    #           </p>
    #         </div>
    #     """
    # )
    
    with gr.Box():
        
        # chatbot = gr.Chatbot()
        # msg = gr.Textbox()
        chatbot = gr.Chatbot([], show_label=False, elem_id="chatbot").style(height="auto")
    
        # with gr.Row():
        with gr.Row(elem_id="prompt-container").style(mobile_collapse=False, equal_height=True):
            with gr.Column(scale=0.85):
                txt = gr.Textbox(
                    show_label=False,
                    placeholder="Type your response and press enter, or record your response",
                ).style(container=False)
            with gr.Column(scale=0.15, min_width=0):
                submit = gr.Button("Submit")
        # gr.Interface(
        #     fn=transcribe, 
        #     inputs=[
        #         gr.Audio(source="microphone", type="filepath", streaming=True), 
        #         "state"
        #     ],
        #     outputs=[
        #         msg,
        #         "state"
        #     ],
        #     live=True)
    
        txt.submit(user, [txt, chatbot], [txt, chatbot], queue=False).then(
            bot, chatbot, chatbot
        )
        submit.click(user, [txt, chatbot], [txt, chatbot], queue=False).then(
            bot, chatbot, chatbot
        )

demo.queue()
demo.launch()