Anonymous0045 commited on
Commit
0a7b900
·
verified ·
1 Parent(s): 2e24877

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -38
app.py CHANGED
@@ -39,7 +39,6 @@ llm = Llama(
39
  n_threads=CPU_THREADS,
40
  n_batch=512,
41
  use_mmap=True,
42
- use_mlock=False,
43
  verbose=False
44
  )
45
 
@@ -47,39 +46,36 @@ print("Model loaded successfully.")
47
 
48
 
49
  # ============================
50
- # Prompt Formatting
51
  # ============================
52
 
53
  SYSTEM_PROMPT = """You are DeepSeek Coder, an expert programming assistant.
54
- You write clean, efficient, production-ready code.
55
- Only explain if user asks.
56
  """
57
 
58
 
59
- def build_prompt(messages):
60
 
61
  prompt = SYSTEM_PROMPT + "\n\n"
62
 
63
- for msg in messages:
64
- if msg["role"] == "user":
65
- prompt += f"User: {msg['content']}\n"
66
- elif msg["role"] == "assistant":
67
- prompt += f"Assistant: {msg['content']}\n"
68
 
69
- prompt += "Assistant:"
70
 
71
  return prompt
72
 
73
 
74
  # ============================
75
- # Streaming Generator
76
  # ============================
77
 
78
- def generate_response(message, history):
79
 
80
- messages = history + [{"role": "user", "content": message}]
81
 
82
- prompt = build_prompt(messages)
83
 
84
  output = ""
85
 
@@ -90,38 +86,18 @@ def generate_response(message, history):
90
  top_p=0.95,
91
  stream=True
92
  ):
93
- text = token["choices"][0]["text"]
94
- output += text
95
  yield output
96
 
97
 
98
  # ============================
99
- # Gradio Chat Interface
100
- # ============================
101
-
102
- def chat(message, history):
103
-
104
- history = history or []
105
-
106
- assistant_response = ""
107
-
108
- for partial in generate_response(message, history):
109
- assistant_response = partial
110
- yield history + [
111
- {"role": "user", "content": message},
112
- {"role": "assistant", "content": assistant_response},
113
- ]
114
-
115
-
116
- # ============================
117
- # Launch UI
118
  # ============================
119
 
120
  demo = gr.ChatInterface(
121
  fn=chat,
122
  title="DeepSeek Coder 1.3B",
123
- description="Production GGUF model running on llama.cpp",
124
- type="messages"
125
  )
126
 
127
  demo.launch(
 
39
  n_threads=CPU_THREADS,
40
  n_batch=512,
41
  use_mmap=True,
 
42
  verbose=False
43
  )
44
 
 
46
 
47
 
48
  # ============================
49
+ # Prompt Builder
50
  # ============================
51
 
52
  SYSTEM_PROMPT = """You are DeepSeek Coder, an expert programming assistant.
53
+ Write clean and efficient code.
54
+ Only explain when asked.
55
  """
56
 
57
 
58
+ def build_prompt(message, history):
59
 
60
  prompt = SYSTEM_PROMPT + "\n\n"
61
 
62
+ for user_msg, assistant_msg in history:
63
+ prompt += f"User: {user_msg}\nAssistant: {assistant_msg}\n"
 
 
 
64
 
65
+ prompt += f"User: {message}\nAssistant:"
66
 
67
  return prompt
68
 
69
 
70
  # ============================
71
+ # Generate Response
72
  # ============================
73
 
74
+ def chat(message, history):
75
 
76
+ history = history or []
77
 
78
+ prompt = build_prompt(message, history)
79
 
80
  output = ""
81
 
 
86
  top_p=0.95,
87
  stream=True
88
  ):
89
+ output += token["choices"][0]["text"]
 
90
  yield output
91
 
92
 
93
  # ============================
94
+ # Launch Gradio ChatInterface
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  # ============================
96
 
97
  demo = gr.ChatInterface(
98
  fn=chat,
99
  title="DeepSeek Coder 1.3B",
100
+ description="Production GGUF model running on llama.cpp"
 
101
  )
102
 
103
  demo.launch(