Agung1453 commited on
Commit
d188887
·
verified ·
1 Parent(s): c3cbe3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -27
app.py CHANGED
@@ -1,42 +1,30 @@
1
  import gradio as gr
2
- from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
3
 
4
- # Load model & tokenizer dari HuggingFace Hub
5
- model_id = "deepseek-ai/DeepSeek-V3.1-Base"
6
 
7
- tokenizer = AutoTokenizer.from_pretrained(model_id)
8
- model = AutoModelForCausalLM.from_pretrained(
9
- model_id,
10
- device_map="auto",
11
- torch_dtype="auto"
12
  )
13
 
14
- # Buat pipeline text-generation
15
- chatbot = pipeline(
16
- "text-generation",
17
- model=model,
18
- tokenizer=tokenizer,
19
- max_new_tokens=512
20
- )
21
-
22
- # Fungsi chatbot
23
  def respond(message, history):
24
  prompt = ""
25
  for user, bot in history:
26
  prompt += f"User: {user}\nAssistant: {bot}\n"
27
  prompt += f"User: {message}\nAssistant:"
28
 
29
- output = chatbot(prompt, do_sample=True, temperature=0.7, top_p=0.9)[0]["generated_text"]
30
-
31
- # Ambil jawaban setelah "Assistant:"
32
- response = output.split("Assistant:")[-1].strip()
33
  return response
34
 
35
- # Gradio UI
36
  with gr.Blocks() as demo:
37
- gr.Markdown("# 🤖 DeepSeek V3.1 Chatbot")
38
- chatbot_ui = gr.Chatbot()
39
- msg = gr.Textbox(placeholder="Tulis pesanmu di sini...")
40
  clear = gr.Button("Clear")
41
 
42
  def user_input(message, history):
@@ -44,7 +32,7 @@ with gr.Blocks() as demo:
44
  history.append((message, response))
45
  return "", history
46
 
47
- msg.submit(user_input, [msg, chatbot_ui], [msg, chatbot_ui])
48
- clear.click(lambda: None, None, chatbot_ui, queue=False)
49
 
50
  demo.launch()
 
1
  import gradio as gr
2
+ from llama_cpp import Llama
3
 
4
+ # Ganti dengan path model GGUF (download dulu ke Space atau pakai hf:// link)
5
+ MODEL_PATH = "DeepSeek-V3.1-Chat-Q4_K_M.gguf"
6
 
7
+ # Load model quantized (ringan untuk CPU 16GB)
8
+ llm = Llama(
9
+ model_path=MODEL_PATH,
10
+ n_ctx=2048,
11
+ n_threads=4
12
  )
13
 
 
 
 
 
 
 
 
 
 
14
  def respond(message, history):
15
  prompt = ""
16
  for user, bot in history:
17
  prompt += f"User: {user}\nAssistant: {bot}\n"
18
  prompt += f"User: {message}\nAssistant:"
19
 
20
+ output = llm(prompt, max_tokens=512, temperature=0.7, top_p=0.9)
21
+ response = output["choices"][0]["text"].strip()
 
 
22
  return response
23
 
 
24
  with gr.Blocks() as demo:
25
+ gr.Markdown("# 🤖 DeepSeek V3.1 Chatbot (Quantized, CPU)")
26
+ chatbot = gr.Chatbot()
27
+ msg = gr.Textbox(placeholder="Tulis pesan di sini...")
28
  clear = gr.Button("Clear")
29
 
30
  def user_input(message, history):
 
32
  history.append((message, response))
33
  return "", history
34
 
35
+ msg.submit(user_input, [msg, chatbot], [msg, chatbot])
36
+ clear.click(lambda: None, None, chatbot, queue=False)
37
 
38
  demo.launch()