raghualgt commited on
Commit
9f3ddb8
·
verified ·
1 Parent(s): 6f375db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -8
app.py CHANGED
@@ -6,14 +6,32 @@ generator = pipeline(
6
  model="deepseek-ai/deepseek-coder-1.3b-instruct"
7
  )
8
 
9
- def generate_code(prompt):
10
- result = generator(prompt, max_length=200)
11
- return result[0]["generated_text"]
12
-
13
- demo = gr.Interface(
14
- fn=generate_code,
15
- inputs="text",
16
- outputs="text",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  title="Python Coding Assistant",
18
  description="Ask Python coding questions"
19
  )
 
6
  model="deepseek-ai/deepseek-coder-1.3b-instruct"
7
  )
8
 
9
+ SYSTEM_PROMPT = """
10
+ You are an expert Python developer.
11
+
12
+ Always:
13
+ - write clean Python code
14
+ - add comments when useful
15
+ - avoid unnecessary explanations
16
+ """
17
+
18
+ def chat(message, history):
19
+
20
+ prompt = SYSTEM_PROMPT + "\nUser: " + message + "\nAssistant:"
21
+
22
+ result = generator(
23
+ prompt,
24
+ max_new_tokens=200,
25
+ temperature=0.2
26
+ )
27
+
28
+ output = result[0]["generated_text"]
29
+
30
+ return output.split("Assistant:")[-1]
31
+
32
+
33
+ demo = gr.ChatInterface(
34
+ fn=chat,
35
  title="Python Coding Assistant",
36
  description="Ask Python coding questions"
37
  )