sapthesh commited on
Commit
7db3c78
Β·
verified Β·
1 Parent(s): 97dafb2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -36
app.py CHANGED
@@ -1,42 +1,38 @@
1
- import warnings
2
  import gradio as gr
3
- from proxy_model import RemoteModelProxy
 
4
 
5
- # Suppress the FutureWarning
6
- warnings.filterwarnings("ignore", category=FutureWarning, module="torch")
7
 
8
- # Load the model via the proxy
9
- model_proxy = RemoteModelProxy("deepseek-ai/DeepSeek-V3")
 
 
 
 
 
10
 
11
- # Define the text classification function
12
- def classify_text(text):
13
- try:
14
- result = model_proxy.classify_text(text)
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
- # Create a Gradio interface
24
- try:
25
- iface = gr.Interface(
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
- # Launch the interface
39
- try:
40
- iface.launch()
41
- except Exception as e:
42
- print(f"Failed to launch Gradio interface: {e}")
 
 
 
 
 
 
 
 
 
 
 
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)