Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,7 +27,7 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
| 27 |
):
|
| 28 |
token = message.choices[0].delta.content
|
| 29 |
response += token
|
| 30 |
-
yield response
|
| 31 |
|
| 32 |
def clear_session():
|
| 33 |
return "", []
|
|
@@ -36,15 +36,17 @@ def modify_system_session(system):
|
|
| 36 |
if not system:
|
| 37 |
system = default_system
|
| 38 |
return system, system, []
|
|
|
|
|
|
|
| 39 |
|
| 40 |
with gr.Blocks() as demo:
|
| 41 |
-
gr.Markdown("<h1 style='text-align: center;'>LLM.C
|
| 42 |
|
| 43 |
with gr.Row():
|
| 44 |
with gr.Column(scale=3):
|
| 45 |
system_input = gr.Textbox(value=default_system, lines=1, label='System Prompt')
|
| 46 |
with gr.Column(scale=1):
|
| 47 |
-
modify_system = gr.Button("🛠️ Set system prompt and clear history"
|
| 48 |
|
| 49 |
system_state = gr.Textbox(value=default_system, visible=False)
|
| 50 |
chatbot = gr.Chatbot(label='LLM.C Chat')
|
|
@@ -54,6 +56,12 @@ with gr.Blocks() as demo:
|
|
| 54 |
clear_history = gr.Button("🧹 Clear history")
|
| 55 |
submit = gr.Button("🚀 Send")
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
with gr.Accordion("Advanced Settings", open=False):
|
| 58 |
max_tokens = gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max New Tokens")
|
| 59 |
temperature = gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature")
|
|
@@ -65,10 +73,16 @@ with gr.Blocks() as demo:
|
|
| 65 |
clear_history.click(fn=clear_session, inputs=[], outputs=[message, chatbot])
|
| 66 |
modify_system.click(fn=modify_system_session, inputs=[system_input], outputs=[system_state, system_input, chatbot])
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
gr.Markdown(
|
| 69 |
"""
|
| 70 |
## About LLM.C
|
| 71 |
-
|
| 72 |
"""
|
| 73 |
)
|
| 74 |
|
|
|
|
| 27 |
):
|
| 28 |
token = message.choices[0].delta.content
|
| 29 |
response += token
|
| 30 |
+
yield history + [(message, response)]
|
| 31 |
|
| 32 |
def clear_session():
|
| 33 |
return "", []
|
|
|
|
| 36 |
if not system:
|
| 37 |
system = default_system
|
| 38 |
return system, system, []
|
| 39 |
+
def use_example(example):
|
| 40 |
+
return example
|
| 41 |
|
| 42 |
with gr.Blocks() as demo:
|
| 43 |
+
gr.Markdown("<h1 style='text-align: center;'>LLM.C Chat Demo</h1>")
|
| 44 |
|
| 45 |
with gr.Row():
|
| 46 |
with gr.Column(scale=3):
|
| 47 |
system_input = gr.Textbox(value=default_system, lines=1, label='System Prompt')
|
| 48 |
with gr.Column(scale=1):
|
| 49 |
+
modify_system = gr.Button("🛠️ Set system prompt and clear history")
|
| 50 |
|
| 51 |
system_state = gr.Textbox(value=default_system, visible=False)
|
| 52 |
chatbot = gr.Chatbot(label='LLM.C Chat')
|
|
|
|
| 56 |
clear_history = gr.Button("🧹 Clear history")
|
| 57 |
submit = gr.Button("🚀 Send")
|
| 58 |
|
| 59 |
+
# New section for example prompts
|
| 60 |
+
gr.Markdown("### Example prompts")
|
| 61 |
+
with gr.Row():
|
| 62 |
+
example1 = gr.Button("🦄 Unicorn Discovery")
|
| 63 |
+
example2 = gr.Button("⏳ Time Travel Paradox")
|
| 64 |
+
|
| 65 |
with gr.Accordion("Advanced Settings", open=False):
|
| 66 |
max_tokens = gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max New Tokens")
|
| 67 |
temperature = gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature")
|
|
|
|
| 73 |
clear_history.click(fn=clear_session, inputs=[], outputs=[message, chatbot])
|
| 74 |
modify_system.click(fn=modify_system_session, inputs=[system_input], outputs=[system_state, system_input, chatbot])
|
| 75 |
|
| 76 |
+
# Event handlers for example prompts
|
| 77 |
+
example1.click(use_example, inputs=[], outputs=[message],
|
| 78 |
+
_js="(x) => 'In a shocking finding, scientist discovered a herd of unicorns living in a remote, previously unexplored valley, in the Andes Mountains. Even more surprising to the researchers was the fact that the unicorns spoke perfect English.'")
|
| 79 |
+
example2.click(use_example, inputs=[], outputs=[message],
|
| 80 |
+
_js="(x) => 'Explain the grandfather paradox in time travel and propose a potential resolution.'")
|
| 81 |
+
|
| 82 |
gr.Markdown(
|
| 83 |
"""
|
| 84 |
## About LLM.C
|
| 85 |
+
some stuff about llmc
|
| 86 |
"""
|
| 87 |
)
|
| 88 |
|