Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,77 +13,71 @@ DEFAULT_TOP_P = 0.95
|
|
| 13 |
|
| 14 |
|
| 15 |
def respond(
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
):
|
| 24 |
-
|
| 25 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 26 |
"""
|
| 27 |
-
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
| 44 |
|
| 45 |
|
| 46 |
"""
|
| 47 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 48 |
"""
|
| 49 |
chatbot = gr.ChatInterface(
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
[
|
| 74 |
-
"Provide the stats of the female workers in the local town's brothel, these stats refer to the number of sexual acts (vaginal, anal, etc) executed by each person and their profficiency at it",
|
| 75 |
-
SYSTEM_PROMPT,
|
| 76 |
-
DEFAULT_TOKENS,
|
| 77 |
-
DEFAULT_TEMPERATURE,
|
| 78 |
-
DEFAULT_TOP_P,
|
| 79 |
-
],
|
| 80 |
-
],
|
| 81 |
)
|
| 82 |
|
| 83 |
with gr.Blocks() as demo:
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
|
| 88 |
if __name__ == "__main__":
|
| 89 |
-
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
def respond(
|
| 16 |
+
message,
|
| 17 |
+
history: list[dict[str, str]],
|
| 18 |
+
system_message,
|
| 19 |
+
max_tokens,
|
| 20 |
+
temperature,
|
| 21 |
+
top_p,
|
| 22 |
+
hf_token: gr.OAuthToken,
|
| 23 |
):
|
| 24 |
+
"""
|
| 25 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 26 |
"""
|
| 27 |
+
client = InferenceClient(token=hf_token.token, model=MODEL)
|
| 28 |
|
| 29 |
+
messages = [{"role": "system", "content": system_message}]
|
| 30 |
+
messages.extend(history)
|
| 31 |
+
messages.append({"role": "user", "content": message})
|
| 32 |
|
| 33 |
+
completion = client.chat_completion(
|
| 34 |
+
messages,
|
| 35 |
+
max_tokens=max_tokens,
|
| 36 |
+
stream=False,
|
| 37 |
+
temperature=temperature,
|
| 38 |
+
top_p=top_p,
|
| 39 |
+
)
|
| 40 |
|
| 41 |
+
for choice in completion.choices:
|
| 42 |
+
response = choice.message.content
|
| 43 |
+
if response:
|
| 44 |
+
response = response.replace("*", "").replace("_", "")
|
| 45 |
+
yield response
|
| 46 |
|
| 47 |
|
| 48 |
"""
|
| 49 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 50 |
"""
|
| 51 |
chatbot = gr.ChatInterface(
|
| 52 |
+
respond,
|
| 53 |
+
type="messages",
|
| 54 |
+
additional_inputs=[
|
| 55 |
+
gr.Textbox(value=SYSTEM_PROMPT, label="System message"),
|
| 56 |
+
gr.Slider(minimum=1, maximum=2048, value=DEFAULT_TOKENS, step=1, label="Max new tokens"),
|
| 57 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=DEFAULT_TEMPERATURE, step=0.1, label="Temperature"),
|
| 58 |
+
gr.Slider(
|
| 59 |
+
minimum=0.1,
|
| 60 |
+
maximum=1.0,
|
| 61 |
+
value=DEFAULT_TOP_P,
|
| 62 |
+
step=0.05,
|
| 63 |
+
label="Top-p (nucleus sampling)",
|
| 64 |
+
),
|
| 65 |
+
],
|
| 66 |
+
# examples=[
|
| 67 |
+
# [
|
| 68 |
+
# "Provide the stats of the female workers in the local town's brothel, these stats refer to the number of sexual acts (vaginal, anal, etc) executed by each person and their profficiency at it",
|
| 69 |
+
# SYSTEM_PROMPT,
|
| 70 |
+
# DEFAULT_TOKENS,
|
| 71 |
+
# DEFAULT_TEMPERATURE,
|
| 72 |
+
# DEFAULT_TOP_P,
|
| 73 |
+
# ],
|
| 74 |
+
# ],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
)
|
| 76 |
|
| 77 |
with gr.Blocks() as demo:
|
| 78 |
+
with gr.Sidebar():
|
| 79 |
+
gr.LoginButton()
|
| 80 |
+
chatbot.render()
|
| 81 |
|
| 82 |
if __name__ == "__main__":
|
| 83 |
+
demo.launch(ssr_mode=False, )
|