update desc
Browse files
app.py
CHANGED
@@ -30,22 +30,21 @@ def predict(inputs, top_p, temperature, top_k, repetition_penalty, history=[]):
|
|
30 |
}
|
31 |
|
32 |
history.append(inputs)
|
|
|
33 |
response = requests.post(API_URL, headers=headers, json=payload, stream=True)
|
34 |
token_counter = 0
|
35 |
-
partial_words = ""
|
|
|
36 |
for chunk in response.iter_lines():
|
|
|
37 |
if chunk:
|
38 |
-
|
39 |
partial_words = partial_words + json.loads(chunk.decode()[5:])['token']['text']
|
40 |
-
#print(partial_words)
|
41 |
-
time.sleep(0.05)
|
42 |
-
#print([(partial_words, "")])
|
43 |
if token_counter == 0:
|
44 |
history.append(" " + partial_words)
|
45 |
else:
|
46 |
history[-1] = partial_words
|
47 |
chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2) ] # convert to tuples of list
|
48 |
-
#yield [(partial_words, history)]
|
49 |
token_counter+=1
|
50 |
yield chat, history #{chatbot: chat, state: history} #[(partial_words, history)]
|
51 |
|
@@ -59,7 +58,7 @@ User: <utterance>
|
|
59 |
Assistant: <utterance>
|
60 |
...
|
61 |
```
|
62 |
-
In this app, you can explore the outputs of a large language
|
63 |
"""
|
64 |
|
65 |
with gr.Blocks(css = "#chatbot {height: 400px; overflow: auto;}") as demo:
|
@@ -83,4 +82,3 @@ with gr.Blocks(css = "#chatbot {height: 400px; overflow: auto;}") as demo:
|
|
83 |
|
84 |
gr.Markdown(description)
|
85 |
demo.queue().launch(debug=True)
|
86 |
-
|
|
|
30 |
}
|
31 |
|
32 |
history.append(inputs)
|
33 |
+
# make a POST request to the API endpoint using the requests.post method, passing in stream=True
|
34 |
response = requests.post(API_URL, headers=headers, json=payload, stream=True)
|
35 |
token_counter = 0
|
36 |
+
partial_words = ""
|
37 |
+
# loop over the response data using the iter_lines method of the response object
|
38 |
for chunk in response.iter_lines():
|
39 |
+
# check whether each line is non-empty
|
40 |
if chunk:
|
41 |
+
# decode each line as response data is in bytes
|
42 |
partial_words = partial_words + json.loads(chunk.decode()[5:])['token']['text']
|
|
|
|
|
|
|
43 |
if token_counter == 0:
|
44 |
history.append(" " + partial_words)
|
45 |
else:
|
46 |
history[-1] = partial_words
|
47 |
chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2) ] # convert to tuples of list
|
|
|
48 |
token_counter+=1
|
49 |
yield chat, history #{chatbot: chat, state: history} #[(partial_words, history)]
|
50 |
|
|
|
58 |
Assistant: <utterance>
|
59 |
...
|
60 |
```
|
61 |
+
In this app, you can explore the outputs of a 20B large language model.
|
62 |
"""
|
63 |
|
64 |
with gr.Blocks(css = "#chatbot {height: 400px; overflow: auto;}") as demo:
|
|
|
82 |
|
83 |
gr.Markdown(description)
|
84 |
demo.queue().launch(debug=True)
|
|