Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -181,37 +181,41 @@ 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 |
-
def
|
187 |
message = message.replace("@์ฌ์ฉ์1@", nickname)
|
188 |
-
|
|
|
|
|
189 |
for partial in generate_text_better_sampling(model, message):
|
190 |
-
|
191 |
-
|
|
|
|
|
|
|
|
|
192 |
|
193 |
css = """
|
194 |
-
|
195 |
-
background-color: #
|
196 |
color: #eee;
|
197 |
border-radius: 10px;
|
198 |
padding: 15px;
|
199 |
-
font-family: '
|
200 |
-
|
201 |
-
.input-area textarea {
|
202 |
-
background-color: #333;
|
203 |
-
color: #eee;
|
204 |
-
border-radius: 8px;
|
205 |
-
border: none;
|
206 |
-
padding: 10px;
|
207 |
-
font-size: 16px;
|
208 |
}
|
209 |
"""
|
210 |
|
211 |
with gr.Blocks(css=css) as demo:
|
212 |
-
|
213 |
-
|
214 |
-
txt.
|
|
|
|
|
|
|
215 |
txt.submit(lambda: "", None, txt) # ์
๋ ฅ์ฐฝ ํด๋ฆฌ์ด
|
216 |
|
217 |
demo.launch()
|
|
|
181 |
|
182 |
yield decoded_text
|
183 |
|
184 |
+
import gradio as gr
|
185 |
+
|
186 |
nickname = "์ฌ์ฉ์1"
|
187 |
|
188 |
+
def stream_respond(message, history):
|
189 |
message = message.replace("@์ฌ์ฉ์1@", nickname)
|
190 |
+
history = history or []
|
191 |
+
bot_response = ""
|
192 |
+
|
193 |
for partial in generate_text_better_sampling(model, message):
|
194 |
+
bot_response = partial
|
195 |
+
temp = history + [(nickname, message), ("๋ด", bot_response)]
|
196 |
+
yield "", temp
|
197 |
+
|
198 |
+
def format_history(history):
|
199 |
+
return "\n\n".join([f"**{who}**: {text}" for who, text in history])
|
200 |
|
201 |
css = """
|
202 |
+
#chatbox {
|
203 |
+
background-color: #111;
|
204 |
color: #eee;
|
205 |
border-radius: 10px;
|
206 |
padding: 15px;
|
207 |
+
font-family: 'D2Coding', monospace;
|
208 |
+
white-space: pre-wrap;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
}
|
210 |
"""
|
211 |
|
212 |
with gr.Blocks(css=css) as demo:
|
213 |
+
state = gr.State([])
|
214 |
+
chat_display = gr.Markdown(elem_id="chatbox")
|
215 |
+
txt = gr.Textbox(placeholder="๋ฉ์์ง๋ฅผ ์
๋ ฅํ์ธ์...", show_label=False)
|
216 |
+
|
217 |
+
txt.submit(stream_respond, [txt, state], [txt, state])
|
218 |
+
state.change(fn=format_history, inputs=state, outputs=chat_display)
|
219 |
txt.submit(lambda: "", None, txt) # ์
๋ ฅ์ฐฝ ํด๋ฆฌ์ด
|
220 |
|
221 |
demo.launch()
|