Update app.py
Browse files
app.py
CHANGED
@@ -64,6 +64,15 @@ def chat(history, system_message, max_tokens, temperature, top_p, top_k, repetit
|
|
64 |
updated_history = call_nvidia_api(history, max_tokens, temperature, top_p)
|
65 |
return updated_history, ""
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
# Gradio interface setup
|
68 |
with gr.Blocks() as demo:
|
69 |
with gr.Row():
|
@@ -87,41 +96,23 @@ with gr.Blocks() as demo:
|
|
87 |
"""
|
88 |
gr.Markdown(description)
|
89 |
chatbox = gr.Textbox(label="What do you want to chat about?", placeholder="Ask me anything.", lines=3)
|
90 |
-
chatbot = gr.ChatInterface(
|
91 |
-
fn=chat,
|
92 |
-
title="LLAMA 2 70B Chatbot",
|
93 |
-
submit_btn="Submit",
|
94 |
-
stop_btn="Stop",
|
95 |
-
retry_btn="🔄 Retry",
|
96 |
-
undo_btn="↩️ Undo",
|
97 |
-
clear_btn="🗑️ Clear",
|
98 |
-
)
|
99 |
system_msg = gr.Textbox(BASE_SYSTEM_MESSAGE, label="System Message", placeholder="System prompt.", lines=5)
|
100 |
max_tokens = gr.Slider(20, 1024, label="Max Tokens", step=20, value=1024, interactive=True)
|
101 |
temperature = gr.Slider(0.0, 1.0, label="Temperature", step=0.1, value=0.2, interactive=True)
|
102 |
top_p = gr.Slider(0.0, 1.0, label="Top P", step=0.05, value=0.7, interactive=True)
|
103 |
chat_history_state = gr.State([])
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
max_tokens_container = gr.Container(max_tokens, label="Max Tokens")
|
109 |
-
temperature_container = gr.Container(temperature, label="Temperature")
|
110 |
-
top_p_container = gr.Container(top_p, label="Top P")
|
111 |
-
|
112 |
-
def update_chatbot(message, chat_history, system_message, max_tokens, temperature, top_p):
|
113 |
-
print("Updating chatbot...")
|
114 |
-
if not chat_history or (chat_history and chat_history[-1]["role"] != "user"):
|
115 |
-
chat_history = user(message, chat_history, system_message if not chat_history else None)
|
116 |
-
else:
|
117 |
-
chat_history = user(message, chat_history)
|
118 |
-
chat_history, _ = chat(chat_history, system_message, max_tokens, temperature, top_p, 40, 1.1)
|
119 |
-
return chat_history
|
120 |
-
|
121 |
-
chatbot.submit(
|
122 |
fn=update_chatbot,
|
123 |
-
inputs=[chatbox, chat_history_state
|
124 |
-
outputs=chat_history_state
|
|
|
|
|
|
|
|
|
|
|
125 |
)
|
126 |
|
127 |
chatbot.clear(
|
|
|
64 |
updated_history = call_nvidia_api(history, max_tokens, temperature, top_p)
|
65 |
return updated_history, ""
|
66 |
|
67 |
+
def update_chatbot(message, chat_history, system_message, max_tokens, temperature, top_p):
|
68 |
+
print("Updating chatbot...")
|
69 |
+
if not chat_history or (chat_history and chat_history[-1]["role"] != "user"):
|
70 |
+
chat_history = user(message, chat_history, system_message if not chat_history else None)
|
71 |
+
else:
|
72 |
+
chat_history = user(message, chat_history)
|
73 |
+
chat_history, _ = call_nvidia_api(chat_history, max_tokens, temperature, top_p)
|
74 |
+
return chat_history
|
75 |
+
|
76 |
# Gradio interface setup
|
77 |
with gr.Blocks() as demo:
|
78 |
with gr.Row():
|
|
|
96 |
"""
|
97 |
gr.Markdown(description)
|
98 |
chatbox = gr.Textbox(label="What do you want to chat about?", placeholder="Ask me anything.", lines=3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
system_msg = gr.Textbox(BASE_SYSTEM_MESSAGE, label="System Message", placeholder="System prompt.", lines=5)
|
100 |
max_tokens = gr.Slider(20, 1024, label="Max Tokens", step=20, value=1024, interactive=True)
|
101 |
temperature = gr.Slider(0.0, 1.0, label="Temperature", step=0.1, value=0.2, interactive=True)
|
102 |
top_p = gr.Slider(0.0, 1.0, label="Top P", step=0.05, value=0.7, interactive=True)
|
103 |
chat_history_state = gr.State([])
|
104 |
|
105 |
+
additional_inputs = [system_msg, max_tokens, temperature, top_p]
|
106 |
+
|
107 |
+
chatbot = gr.ChatInterface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
fn=update_chatbot,
|
109 |
+
inputs=[chatbox, chat_history_state],
|
110 |
+
outputs=chat_history_state,
|
111 |
+
additional_inputs=additional_inputs,
|
112 |
+
title="LLAMA 2 70B Chatbot",
|
113 |
+
submit_btn="Submit",
|
114 |
+
clear_btn="🗑️ Clear",
|
115 |
+
textbox=chatbox,
|
116 |
)
|
117 |
|
118 |
chatbot.clear(
|