Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -95,37 +95,43 @@ def add_witty_humor_buttons():
|
|
| 95 |
|
| 96 |
# Function to Stream Inference Client for Inference Endpoint Responses
|
| 97 |
def StreamLLMChatResponse(prompt):
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
def query(payload):
|
| 131 |
response = requests.post(API_URL, headers=headers, json=payload)
|
|
|
|
| 95 |
|
| 96 |
# Function to Stream Inference Client for Inference Endpoint Responses
|
| 97 |
def StreamLLMChatResponse(prompt):
|
| 98 |
+
|
| 99 |
+
try:
|
| 100 |
+
endpoint_url = API_URL
|
| 101 |
+
hf_token = API_KEY
|
| 102 |
+
client = InferenceClient(endpoint_url, token=hf_token)
|
| 103 |
+
gen_kwargs = dict(
|
| 104 |
+
max_new_tokens=512,
|
| 105 |
+
top_k=30,
|
| 106 |
+
top_p=0.9,
|
| 107 |
+
temperature=0.2,
|
| 108 |
+
repetition_penalty=1.02,
|
| 109 |
+
stop_sequences=["\nUser:", "<|endoftext|>", "</s>"],
|
| 110 |
+
)
|
| 111 |
+
stream = client.text_generation(prompt, stream=True, details=True, **gen_kwargs)
|
| 112 |
+
report=[]
|
| 113 |
+
res_box = st.empty()
|
| 114 |
+
collected_chunks=[]
|
| 115 |
+
collected_messages=[]
|
| 116 |
+
for r in stream:
|
| 117 |
+
if r.token.special:
|
| 118 |
+
continue
|
| 119 |
+
if r.token.text in gen_kwargs["stop_sequences"]:
|
| 120 |
+
break
|
| 121 |
+
collected_chunks.append(r.token.text)
|
| 122 |
+
chunk_message = r.token.text
|
| 123 |
+
collected_messages.append(chunk_message)
|
| 124 |
+
try:
|
| 125 |
+
report.append(r.token.text)
|
| 126 |
+
if len(r.token.text) > 0:
|
| 127 |
+
result="".join(report).strip()
|
| 128 |
+
res_box.markdown(f'*{result}*')
|
| 129 |
+
except:
|
| 130 |
+
st.write(' ')
|
| 131 |
+
except:
|
| 132 |
+
st.write('DromeLlama is asleep. Starting up now on A10 - please give 5 minutes then retry as KEDA scales up from zero to activate running container(s).')
|
| 133 |
+
|
| 134 |
+
|
| 135 |
|
| 136 |
def query(payload):
|
| 137 |
response = requests.post(API_URL, headers=headers, json=payload)
|