Spaces:
Sleeping
Sleeping
Add DeepHat app
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
|
| 4 |
+
model_name = "DeepHat/DeepHat-V1-7B"
|
| 5 |
+
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 9 |
+
model_name,
|
| 10 |
+
device_map="auto",
|
| 11 |
+
low_cpu_mem_usage=True
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
def chat(input_text):
|
| 15 |
+
messages = [
|
| 16 |
+
{"role": "system", "content": "You are a cybersecurity expert."},
|
| 17 |
+
{"role": "user", "content": input_text}
|
| 18 |
+
]
|
| 19 |
+
|
| 20 |
+
text = tokenizer.apply_chat_template(
|
| 21 |
+
messages,
|
| 22 |
+
tokenize=False,
|
| 23 |
+
add_generation_prompt=True
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 27 |
+
outputs = model.generate(**inputs, max_new_tokens=120)
|
| 28 |
+
|
| 29 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 30 |
+
|
| 31 |
+
gr.Interface(fn=chat, inputs="text", outputs="text").launch()
|