Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -181,18 +181,37 @@ def generate_text_better_sampling(model, prompt, max_len=100, max_gen=98, top_k=
|
|
181 |
|
182 |
yield decoded_text
|
183 |
|
184 |
-
nickname = "์ฌ์ฉ์1"
|
185 |
|
186 |
-
|
187 |
-
message = message.replace("@์ฌ์ฉ์1@", nickname)
|
188 |
-
response = ""
|
189 |
-
for partial in generate_text_better_sampling(model, message):
|
190 |
-
response = partial
|
191 |
-
yield response
|
192 |
|
193 |
-
|
194 |
-
fn=respond,
|
195 |
-
title="InteractGPT",
|
196 |
-
)
|
197 |
|
198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
|
182 |
yield decoded_text
|
183 |
|
|
|
184 |
|
185 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
186 |
|
187 |
+
nickname = "์ฌ์ฉ์"
|
|
|
|
|
|
|
188 |
|
189 |
+
def respond(message, history):
|
190 |
+
message = message.replace("@์ฌ์ฉ์1@", nickname)
|
191 |
+
history = history or []
|
192 |
+
bot_response = ""
|
193 |
+
for partial in generate_text_better_sampling(model, message):
|
194 |
+
bot_response = partial
|
195 |
+
# history์ ๋ฉ์์ง์ ๋ด ์๋ต์ ๋ฃ๊ณ , ์ค์๊ฐ ์
๋ฐ์ดํธ์ฉ์ผ๋ก yield
|
196 |
+
yield history + [(nickname, message), ("๋ด", bot_response)]
|
197 |
+
|
198 |
+
with gr.Blocks() as demo:
|
199 |
+
chat_history = gr.State([]) # ๋ํ ๊ธฐ๋ก ์ ์ฅ์ฉ
|
200 |
+
chatbot = gr.Chatbot() # ์ ์! ๊ทธ๋ฅ ๋น ๋ณ์๋ก ์ ์ธ๋ง ํจ, ์ค์ UI๋ ์ง์ ๋ง๋ฆ
|
201 |
+
chat_box = gr.Markdown()
|
202 |
+
user_input = gr.Textbox(show_label=False, placeholder="๋ฉ์์ง๋ฅผ ์
๋ ฅํ์ธ์...")
|
203 |
+
|
204 |
+
def update_chatbox(history):
|
205 |
+
# history๋ฅผ markdown ํ์์ผ๋ก ๋ณํ
|
206 |
+
return "\n\n".join([f"**{who}**: {text}" for who, text in history])
|
207 |
+
|
208 |
+
# ์ค์๊ฐ ์คํธ๋ฆฌ๋ฐ์ผ๋ก ๋ํ ๋ด์ญ ์
๋ฐ์ดํธ
|
209 |
+
def stream_response(message, history):
|
210 |
+
# respond ํจ์ ํธ์ถํด์ ์คํธ๋ฆฌ๋ฐ yield ์ฒ๋ฆฌ
|
211 |
+
for updated_history in respond(message, history):
|
212 |
+
yield update_chatbox(updated_history), updated_history
|
213 |
+
|
214 |
+
user_input.submit(stream_response, inputs=[user_input, chat_history], outputs=[chat_box, chat_history])
|
215 |
+
user_input.submit(lambda: "", None, user_input) # ์
๋ ฅ์ฐฝ ์ด๊ธฐํ
|
216 |
+
|
217 |
+
demo.launch()
|