Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,28 +4,23 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
4 |
model_id = "deepseek-ai/DeepSeek-V3"
|
5 |
|
6 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
7 |
-
model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True) #
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
14 |
outputs = model.generate(**inputs, max_new_tokens=50) # Adjust max_new_tokens as needed
|
15 |
-
|
16 |
-
|
17 |
-
# Example usage (for testing in your app.py):
|
18 |
-
if __name__ == "__main__":
|
19 |
-
prompt = "Write a short story about a cat who can talk."
|
20 |
-
response = generate_text(prompt)
|
21 |
-
print(f"Prompt: {prompt}\nResponse: {response}")
|
22 |
|
23 |
iface = gr.ChatInterface(
|
24 |
fn=predict,
|
25 |
-
inputs=gr.Chatbox(
|
26 |
-
outputs=gr.Chatbot(
|
27 |
-
title="DeepSeek-V3 Chatbot",
|
28 |
-
description="Chat with the DeepSeek-V3 model from Hugging Face.",
|
29 |
)
|
30 |
|
31 |
iface.launch()
|
|
|
4 |
model_id = "deepseek-ai/DeepSeek-V3"
|
5 |
|
6 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True) # ADD trust_remote_code=True
|
8 |
+
|
9 |
+
def predict(message, history):
|
10 |
+
prompt = tokenizer.apply_chat_template(
|
11 |
+
[{"role": "user", "content": message}],
|
12 |
+
tokenize=False,
|
13 |
+
add_generation_prompt=True
|
14 |
+
)
|
15 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda") # Assuming you have CUDA available in your Space
|
16 |
outputs = model.generate(**inputs, max_new_tokens=50) # Adjust max_new_tokens as needed
|
17 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
18 |
+
return response
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
iface = gr.ChatInterface(
|
21 |
fn=predict,
|
22 |
+
inputs=gr.Chatbox(),
|
23 |
+
outputs=gr.Chatbot()
|
|
|
|
|
24 |
)
|
25 |
|
26 |
iface.launch()
|