Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -182,6 +182,8 @@ def generate_text_better_sampling(model, prompt, max_len=100, max_gen=98, top_k=
|
|
182 |
|
183 |
yield decoded_text
|
184 |
|
|
|
|
|
185 |
nickname = "사용자"
|
186 |
|
187 |
def respond(message, chat_history):
|
@@ -189,14 +191,28 @@ def respond(message, chat_history):
|
|
189 |
response = ""
|
190 |
for partial in generate_text_better_sampling(model, message):
|
191 |
response = partial
|
192 |
-
|
|
|
193 |
|
194 |
with gr.Blocks() as demo:
|
195 |
-
|
196 |
-
|
197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
|
199 |
-
|
200 |
-
clear.click(lambda: [], None, chatbot)
|
201 |
|
202 |
demo.launch()
|
|
|
182 |
|
183 |
yield decoded_text
|
184 |
|
185 |
+
import gradio as gr
|
186 |
+
|
187 |
nickname = "사용자"
|
188 |
|
189 |
def respond(message, chat_history):
|
|
|
191 |
response = ""
|
192 |
for partial in generate_text_better_sampling(model, message):
|
193 |
response = partial
|
194 |
+
chat_history = chat_history + [(message, response)]
|
195 |
+
yield chat_history, ""
|
196 |
|
197 |
with gr.Blocks() as demo:
|
198 |
+
chat_history = gr.State([])
|
199 |
+
|
200 |
+
with gr.Column():
|
201 |
+
chat_display = gr.Markdown(value="", elem_id="chat_display", label="대화창")
|
202 |
+
msg = gr.Textbox(placeholder="말 걸어봐!", label="입력")
|
203 |
+
clear = gr.Button("초기화")
|
204 |
+
|
205 |
+
def update_chat_display(history):
|
206 |
+
formatted = ""
|
207 |
+
for user_msg, bot_msg in history:
|
208 |
+
formatted += f"**사용자:** {user_msg}\n\n"
|
209 |
+
formatted += f"**InteractGPT:** {bot_msg}\n\n---\n\n"
|
210 |
+
return formatted
|
211 |
+
|
212 |
+
msg.submit(respond, inputs=[msg, chat_history], outputs=[chat_history, msg]).then(
|
213 |
+
update_chat_display, inputs=chat_history, outputs=chat_display
|
214 |
+
)
|
215 |
|
216 |
+
clear.click(lambda: ([], ""), None, [chat_history, chat_display])
|
|
|
217 |
|
218 |
demo.launch()
|