Spaces:
Sleeping
Sleeping
File size: 1,124 Bytes
171f2ef 9602bb7 171f2ef 9602bb7 21916d9 fdbc2bf 9602bb7 0d2c9df 171f2ef 9602bb7 171f2ef 9602bb7 0d2c9df fdbc2bf 0d2c9df 171f2ef 9602bb7 0d2c9df 9602bb7 171f2ef 551e9e2 |
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 |
import gradio as gr
from comp import generate_response
# --- Gradio UI ---
with gr.Blocks() as demo:
gr.Markdown("# Ling Playground")
chatbot = gr.Chatbot()
msg = gr.Textbox()
clear = gr.ClearButton([msg, chatbot])
def user(user_message, history):
return "", history + [[user_message, None]]
def bot(history):
user_message = history[-1][0]
history[-1][1] = ""
for response in generate_response(user_message, history[:-1]):
if "</think>" in response:
parts = response.split("</think>", 1)
thinking_text = parts[0].replace("<think>", "")
body_text = parts[1]
md_output = f"**Thinking...**\n```\n{thinking_text}\n```\n\n{body_text}"
history[-1][1] = md_output
else:
history[-1][1] = response
yield history
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
bot, chatbot, chatbot
)
clear.click(lambda: None, None, chatbot, queue=False)
if __name__ == "__main__":
demo.launch() |