Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,42 +1,38 @@
|
|
1 |
-
import warnings
|
2 |
import gradio as gr
|
3 |
-
from
|
|
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
return result
|
16 |
-
except Exception as e:
|
17 |
-
print(f"Error during text classification: {e}")
|
18 |
-
return {
|
19 |
-
"Predicted Class": "Error",
|
20 |
-
"Probabilities": []
|
21 |
-
}
|
22 |
|
23 |
-
#
|
24 |
-
|
25 |
-
|
26 |
-
fn=classify_text, # Function to call
|
27 |
-
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."), # Input component
|
28 |
-
outputs=[
|
29 |
-
gr.Label(label="Predicted Class"), # Output component for predicted class
|
30 |
-
gr.Label(label="Probabilities") # Output component for probabilities
|
31 |
-
],
|
32 |
-
title="DeepSeek-V3 Text Classification",
|
33 |
-
description="Classify text using the DeepSeek-V3 model."
|
34 |
-
)
|
35 |
-
except Exception as e:
|
36 |
-
print(f"Failed to create Gradio interface: {e}")
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
import torch
|
4 |
|
5 |
+
# Model and Tokenizer from Hugging Face Hub
|
6 |
+
model_name = "deepseek-ai/DeepSeek-V3"
|
7 |
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
model = AutoModelForCausalLM.from_pretrained(
|
10 |
+
model_name,
|
11 |
+
torch_dtype=torch.bfloat16, # Use bfloat16 for faster and less memory-intensive inference if possible
|
12 |
+
trust_remote_code=True, # Important for models with custom code
|
13 |
+
device_map="auto" # Automatically use available GPU if possible
|
14 |
+
)
|
15 |
|
16 |
+
def generate_response(prompt, history=[]):
|
17 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
18 |
+
outputs = model.generate(**inputs, max_new_tokens=500) # Adjust max_new_tokens as needed
|
19 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
# Basic chat history handling (optional, can be improved)
|
22 |
+
history.append((prompt, response)) # Append user prompt and model response to history
|
23 |
+
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
+
iface = gr.ChatInterface(
|
26 |
+
fn=generate_response,
|
27 |
+
inputs=gr.Chatbox(lines=7, placeholder="Type your message here..."),
|
28 |
+
outputs="text",
|
29 |
+
title="DeepSeek-V3 Chatbot",
|
30 |
+
description="Chat with the DeepSeek-V3 model. Please be patient, initial loading might take a few minutes. For better performance, use a Space with a GPU.",
|
31 |
+
examples=[
|
32 |
+
"Hello, how are you?",
|
33 |
+
"What is the capital of France?",
|
34 |
+
"Tell me a joke."
|
35 |
+
]
|
36 |
+
)
|
37 |
+
|
38 |
+
iface.launch(share=False)
|