Spaces:
Sleeping
Sleeping
Update app.py retry button
Browse files
app.py
CHANGED
|
@@ -23,9 +23,6 @@ selected_model = "mistralai/Mixtral-8x7B-Instruct-v0.1"
|
|
| 23 |
|
| 24 |
client = InferenceClient(selected_model)
|
| 25 |
|
| 26 |
-
def query_submit(user_message, history):
|
| 27 |
-
return "", history + [[user_message, None]]
|
| 28 |
-
|
| 29 |
def format_prompt(query, history, lookback):
|
| 30 |
prompt = "Responses should be no more than 100 words long.\n"
|
| 31 |
|
|
@@ -35,6 +32,9 @@ def format_prompt(query, history, lookback):
|
|
| 35 |
prompt += f"[INST] {query} [/INST]"
|
| 36 |
|
| 37 |
return prompt
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
def query_completion(
|
| 40 |
query,
|
|
@@ -64,24 +64,62 @@ def query_completion(
|
|
| 64 |
history[-1][1] += response.token.text
|
| 65 |
yield history
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
"""
|
| 69 |
Chat UI using Gradio Blocks.
|
| 70 |
|
| 71 |
-
Blocks preferred for lower-level
|
| 72 |
|
| 73 |
TODOs:
|
| 74 |
- State management for dynamic components update.
|
| 75 |
-
- Add
|
| 76 |
* Placeholder added for now.
|
| 77 |
- Add functionality to retry button.
|
| 78 |
* Placeholder added for now.
|
| 79 |
- Add dropdown for model selection.
|
| 80 |
-
|
| 81 |
|
| 82 |
"""
|
| 83 |
|
| 84 |
with gr.Blocks() as chatUI:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
with gr.Row():
|
| 86 |
chatOutput = gr.Chatbot(
|
| 87 |
bubble_full_width = False,
|
|
@@ -98,16 +136,11 @@ with gr.Blocks() as chatUI:
|
|
| 98 |
submitButton = gr.Button("Submit", scale = 1)
|
| 99 |
|
| 100 |
with gr.Row():
|
| 101 |
-
retry = gr.Button("Retry (null)")
|
| 102 |
-
clear = gr.ClearButton([queryInput, chatOutput])
|
| 103 |
-
|
| 104 |
-
with gr.Row():
|
| 105 |
-
modelSelect = gr.Dropdown(
|
| 106 |
-
label = "Model selection:",
|
| 107 |
-
)
|
| 108 |
fileUpload = gr.File(
|
| 109 |
height = 100,
|
| 110 |
)
|
|
|
|
|
|
|
| 111 |
|
| 112 |
with gr.Row():
|
| 113 |
with gr.Accordion(label = "Expand for edit system prompt:"):
|
|
@@ -118,11 +151,11 @@ with gr.Blocks() as chatUI:
|
|
| 118 |
scale = 4,
|
| 119 |
)
|
| 120 |
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
# gr.State()
|
| 125 |
|
|
|
|
| 126 |
queryInput.submit(
|
| 127 |
fn = query_submit,
|
| 128 |
inputs = [queryInput, chatOutput],
|
|
@@ -145,5 +178,12 @@ with gr.Blocks() as chatUI:
|
|
| 145 |
outputs = [chatOutput],
|
| 146 |
)
|
| 147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
chatUI.queue()
|
| 149 |
chatUI.launch(show_api = False)
|
|
|
|
| 23 |
|
| 24 |
client = InferenceClient(selected_model)
|
| 25 |
|
|
|
|
|
|
|
|
|
|
| 26 |
def format_prompt(query, history, lookback):
|
| 27 |
prompt = "Responses should be no more than 100 words long.\n"
|
| 28 |
|
|
|
|
| 32 |
prompt += f"[INST] {query} [/INST]"
|
| 33 |
|
| 34 |
return prompt
|
| 35 |
+
|
| 36 |
+
def query_submit(user_message, history):
|
| 37 |
+
return "", history + [[user_message, None]]
|
| 38 |
|
| 39 |
def query_completion(
|
| 40 |
query,
|
|
|
|
| 64 |
history[-1][1] += response.token.text
|
| 65 |
yield history
|
| 66 |
|
| 67 |
+
def retry_query(history):
|
| 68 |
+
history,
|
| 69 |
+
lookback = 3,
|
| 70 |
+
max_new_tokens = 256,
|
| 71 |
+
):
|
| 72 |
+
|
| 73 |
+
query = history[-1][0]
|
| 74 |
+
history[-1][1] = None
|
| 75 |
+
|
| 76 |
+
generateKwargs = dict(
|
| 77 |
+
max_new_tokens = max_new_tokens,
|
| 78 |
+
seed = 1337,
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
formatted_query = format_prompt(query, history, lookback)
|
| 82 |
+
|
| 83 |
+
stream = client.text_generation(
|
| 84 |
+
formatted_query,
|
| 85 |
+
**generateKwargs,
|
| 86 |
+
stream = True,
|
| 87 |
+
details = True,
|
| 88 |
+
return_full_text = False
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
history[-1][1] = ""
|
| 92 |
+
|
| 93 |
+
for response in stream:
|
| 94 |
+
history[-1][1] += response.token.text
|
| 95 |
+
yield history
|
| 96 |
+
|
| 97 |
|
| 98 |
"""
|
| 99 |
Chat UI using Gradio Blocks.
|
| 100 |
|
| 101 |
+
Blocks preferred for "lower-level" layout control and state management.
|
| 102 |
|
| 103 |
TODOs:
|
| 104 |
- State management for dynamic components update.
|
| 105 |
+
- Add scratchpad readout to the right of chat log.
|
| 106 |
* Placeholder added for now.
|
| 107 |
- Add functionality to retry button.
|
| 108 |
* Placeholder added for now.
|
| 109 |
- Add dropdown for model selection.
|
| 110 |
+
* Placeholder added for now.
|
| 111 |
|
| 112 |
"""
|
| 113 |
|
| 114 |
with gr.Blocks() as chatUI:
|
| 115 |
+
# gr.State()
|
| 116 |
+
|
| 117 |
+
with gr.Row():
|
| 118 |
+
modelSelect = gr.Dropdown(
|
| 119 |
+
label = "Model selection:",
|
| 120 |
+
scale = 0.5,
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
with gr.Row():
|
| 124 |
chatOutput = gr.Chatbot(
|
| 125 |
bubble_full_width = False,
|
|
|
|
| 136 |
submitButton = gr.Button("Submit", scale = 1)
|
| 137 |
|
| 138 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
fileUpload = gr.File(
|
| 140 |
height = 100,
|
| 141 |
)
|
| 142 |
+
retryButton = gr.Button("Retry")
|
| 143 |
+
clearButton = gr.ClearButton([queryInput, chatOutput])
|
| 144 |
|
| 145 |
with gr.Row():
|
| 146 |
with gr.Accordion(label = "Expand for edit system prompt:"):
|
|
|
|
| 151 |
scale = 4,
|
| 152 |
)
|
| 153 |
|
| 154 |
+
|
| 155 |
+
"""
|
| 156 |
+
Event functions
|
|
|
|
| 157 |
|
| 158 |
+
"""
|
| 159 |
queryInput.submit(
|
| 160 |
fn = query_submit,
|
| 161 |
inputs = [queryInput, chatOutput],
|
|
|
|
| 178 |
outputs = [chatOutput],
|
| 179 |
)
|
| 180 |
|
| 181 |
+
retryButton.click(
|
| 182 |
+
fn = retry_query,
|
| 183 |
+
inputs = [chatOutput],
|
| 184 |
+
outputs = [chatOutput],
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
+
|
| 188 |
chatUI.queue()
|
| 189 |
chatUI.launch(show_api = False)
|