Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
"""
|
| 7 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
-
|
| 9 |
|
| 10 |
def respond(
|
| 11 |
message,
|
|
@@ -27,27 +24,27 @@ def respond(
|
|
| 27 |
|
| 28 |
response = ""
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
temperature=temperature,
|
| 35 |
top_p=top_p,
|
|
|
|
| 36 |
):
|
| 37 |
-
token = message.choices[0].delta.content
|
| 38 |
-
|
| 39 |
response += token
|
| 40 |
yield response
|
| 41 |
|
| 42 |
-
|
| 43 |
-
"""
|
| 44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 45 |
-
"""
|
| 46 |
demo = gr.ChatInterface(
|
| 47 |
respond,
|
| 48 |
additional_inputs=[
|
| 49 |
-
gr.Textbox(value="You are a
|
| 50 |
-
gr.Slider(minimum=1, maximum=
|
| 51 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 52 |
gr.Slider(
|
| 53 |
minimum=0.1,
|
|
@@ -57,8 +54,9 @@ demo = gr.ChatInterface(
|
|
| 57 |
label="Top-p (nucleus sampling)",
|
| 58 |
),
|
| 59 |
],
|
|
|
|
|
|
|
| 60 |
)
|
| 61 |
|
| 62 |
-
|
| 63 |
if __name__ == "__main__":
|
| 64 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
# Replace with your actual model path on HF Hub
|
| 5 |
+
client = InferenceClient("dexcommunity/dex")
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def respond(
|
| 8 |
message,
|
|
|
|
| 24 |
|
| 25 |
response = ""
|
| 26 |
|
| 27 |
+
# NOTE: For causal models like Dex, use `client.text_generation()` instead of `chat_completion`
|
| 28 |
+
prompt = "\n".join([f"User: {m['content']}" if m["role"] == "user" else f"Dex: {m['content']}" for m in messages])
|
| 29 |
+
prompt += "\nDex:"
|
| 30 |
+
|
| 31 |
+
for token in client.text_generation(
|
| 32 |
+
prompt,
|
| 33 |
+
max_new_tokens=max_tokens,
|
| 34 |
+
do_sample=True,
|
| 35 |
temperature=temperature,
|
| 36 |
top_p=top_p,
|
| 37 |
+
stream=True
|
| 38 |
):
|
|
|
|
|
|
|
| 39 |
response += token
|
| 40 |
yield response
|
| 41 |
|
| 42 |
+
# Gradio Chat Interface
|
|
|
|
|
|
|
|
|
|
| 43 |
demo = gr.ChatInterface(
|
| 44 |
respond,
|
| 45 |
additional_inputs=[
|
| 46 |
+
gr.Textbox(value="You are a helpful Indian AI assistant named Dex.", label="System message"),
|
| 47 |
+
gr.Slider(minimum=1, maximum=1024, value=256, step=1, label="Max new tokens"),
|
| 48 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 49 |
gr.Slider(
|
| 50 |
minimum=0.1,
|
|
|
|
| 54 |
label="Top-p (nucleus sampling)",
|
| 55 |
),
|
| 56 |
],
|
| 57 |
+
title="🛡️ Dex - Indian Cybersecurity Chatbot",
|
| 58 |
+
description="Dex is a cybersecurity-trained AI assistant that can help you understand infosec, CTFs, payloads, and general queries. Created by ghosthets (Gaurav Chouhan)."
|
| 59 |
)
|
| 60 |
|
|
|
|
| 61 |
if __name__ == "__main__":
|
| 62 |
+
demo.launch()
|