himu1780 commited on
Commit
e49dba0
·
verified ·
1 Parent(s): 07fb626

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -26,8 +26,8 @@ def chat_function(user_message, history):
26
  response = generator(
27
  prompt,
28
  max_new_tokens=250, # Give it enough space to write a full function
29
- temperature=0.4, # Low temperature = Focused logic (No creative babbling)
30
- repetition_penalty=1.2, # STRICT penalty. If it repeats "Hello", it gets banned.
31
  do_sample=True,
32
  pad_token_id=tokenizer.eos_token_id
33
  )
@@ -36,27 +36,24 @@ def chat_function(user_message, history):
36
  full_text = response[0]['generated_text']
37
 
38
  # Isolate just the new code
39
- # We split by "### Response:" to get the answer
40
  answer_part = full_text.split("### Response:")[-1].strip()
41
 
42
  # Ensure the formatting looks nice in the chat
43
- # We stripped the ```python start, so we add it back for the UI
44
  if not answer_part.startswith("```"):
45
  answer_part = "```python\n" + answer_part
46
 
47
  return answer_part
48
 
49
- # 6. Launch the Chat Interface
50
  demo = gr.ChatInterface(
51
  fn=chat_function,
52
- title="🐍 AI Python Assistant",
53
  description="I am trained! Ask me to 'Write a function to...' or 'Create a loop...'",
54
  examples=[
55
  "Write a python function to add two numbers",
56
  "Create a loop from 1 to 10",
57
  "Write a script to calculate the area of a circle"
58
- ],
59
- theme="soft"
60
  )
61
 
62
  demo.launch()
 
26
  response = generator(
27
  prompt,
28
  max_new_tokens=250, # Give it enough space to write a full function
29
+ temperature=0.4, # Low temperature = Focused logic
30
+ repetition_penalty=1.2, # STRICT penalty. Bans "Hello World" loops.
31
  do_sample=True,
32
  pad_token_id=tokenizer.eos_token_id
33
  )
 
36
  full_text = response[0]['generated_text']
37
 
38
  # Isolate just the new code
 
39
  answer_part = full_text.split("### Response:")[-1].strip()
40
 
41
  # Ensure the formatting looks nice in the chat
 
42
  if not answer_part.startswith("```"):
43
  answer_part = "```python\n" + answer_part
44
 
45
  return answer_part
46
 
47
+ # 6. Launch the Chat Interface (Fixed: No theme argument)
48
  demo = gr.ChatInterface(
49
  fn=chat_function,
50
+ title="🐍 AI Python Graduate (Step 1000)",
51
  description="I am trained! Ask me to 'Write a function to...' or 'Create a loop...'",
52
  examples=[
53
  "Write a python function to add two numbers",
54
  "Create a loop from 1 to 10",
55
  "Write a script to calculate the area of a circle"
56
+ ]
 
57
  )
58
 
59
  demo.launch()