Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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()
|
| 33 |
-
issue_type = label_to_issue_type.get(label, "Error")
|
| 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.
|
| 85 |
-
"
|
| 86 |
-
"Give only a factual answer.\n\n"
|
| 87 |
f"Question: {query.strip()}\n\nAnswer:"
|
| 88 |
)
|
| 89 |
|
| 90 |
try:
|
| 91 |
-
result = qa_pipeline(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 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:
|