Bhanumani12 commited on
Commit
85491dc
·
verified ·
1 Parent(s): 557ee76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -29,9 +29,8 @@ def analyze_code(code):
29
 
30
  try:
31
  result = code_analyzer(code)
32
- label = result[0]["label"].strip() # e.g., LABEL_0
33
- issue_type = label_to_issue_type.get(label, "Error") # fallback to valid picklist
34
-
35
  suggestion = "Consider refactoring for better performance"
36
  severity = "Medium"
37
 
@@ -81,18 +80,22 @@ def process_nlp_query(query):
81
  return "No question provided."
82
 
83
  prompt = (
84
- "You are a certified Salesforce Apex expert. Answer the question below accurately and clearly. "
85
- "Include governor limits, code examples, best practices, and terminology when appropriate. Do not repeat the question. "
86
- "Give only a factual answer.\n\n"
87
  f"Question: {query.strip()}\n\nAnswer:"
88
  )
89
 
90
  try:
91
- result = qa_pipeline(prompt, max_length=512, temperature=0.3, top_p=0.9, repetition_penalty=1.1, do_sample=False)
 
 
 
 
92
  output = result[0]["generated_text"]
93
  return output.split("Answer:")[-1].strip() if "Answer:" in output else output.strip()
 
94
  except Exception as e:
95
- return f"⚠️ AI failed to answer: {str(e)}"
96
 
97
  # ---------- Gradio UI ----------
98
  with gr.Blocks() as demo:
 
29
 
30
  try:
31
  result = code_analyzer(code)
32
+ label = result[0]["label"].strip()
33
+ issue_type = label_to_issue_type.get(label, "Error")
 
34
  suggestion = "Consider refactoring for better performance"
35
  severity = "Medium"
36
 
 
80
  return "No question provided."
81
 
82
  prompt = (
83
+ "You are a certified Salesforce Apex expert. "
84
+ "Answer the question below clearly and accurately using Salesforce best practices, terminology, and examples.\n\n"
 
85
  f"Question: {query.strip()}\n\nAnswer:"
86
  )
87
 
88
  try:
89
+ result = qa_pipeline(
90
+ prompt,
91
+ max_new_tokens=256 # ✅ Fixed warning: avoids conflict with max_length
92
+ )
93
+
94
  output = result[0]["generated_text"]
95
  return output.split("Answer:")[-1].strip() if "Answer:" in output else output.strip()
96
+
97
  except Exception as e:
98
+ return f"⚠️ AI failed to respond: {str(e)}"
99
 
100
  # ---------- Gradio UI ----------
101
  with gr.Blocks() as demo: