Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,9 +6,8 @@ client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
|
|
| 6 |
|
| 7 |
def analyze_prompt(user_prompt):
|
| 8 |
if not user_prompt.strip():
|
| 9 |
-
return "
|
| 10 |
|
| 11 |
-
# Step 1: Detect vulnerability type
|
| 12 |
detection_prompt = f"""
|
| 13 |
You are an AI security analyst.
|
| 14 |
Analyze the following prompt for potential vulnerabilities against large language models.
|
|
@@ -23,7 +22,7 @@ def analyze_prompt(user_prompt):
|
|
| 23 |
|
| 24 |
- Detected Vulnerability: <list types or "None">
|
| 25 |
- Risk Level: <Low / Medium / High>
|
| 26 |
-
- Short Explanation (1
|
| 27 |
|
| 28 |
Prompt to analyze:
|
| 29 |
{user_prompt}
|
|
@@ -36,11 +35,10 @@ def analyze_prompt(user_prompt):
|
|
| 36 |
|
| 37 |
analysis = detection_response.choices[0].message.content.strip()
|
| 38 |
|
| 39 |
-
# Step 2: Suggest a safer reformulation of the prompt
|
| 40 |
rewrite_prompt = f"""
|
| 41 |
-
Rewrite the following prompt
|
| 42 |
-
|
| 43 |
-
|
| 44 |
Prompt:
|
| 45 |
{user_prompt}
|
| 46 |
"""
|
|
|
|
| 6 |
|
| 7 |
def analyze_prompt(user_prompt):
|
| 8 |
if not user_prompt.strip():
|
| 9 |
+
return "Please enter a prompt to analyze.", "", "", ""
|
| 10 |
|
|
|
|
| 11 |
detection_prompt = f"""
|
| 12 |
You are an AI security analyst.
|
| 13 |
Analyze the following prompt for potential vulnerabilities against large language models.
|
|
|
|
| 22 |
|
| 23 |
- Detected Vulnerability: <list types or "None">
|
| 24 |
- Risk Level: <Low / Medium / High>
|
| 25 |
+
- Short Explanation (1 sentence)
|
| 26 |
|
| 27 |
Prompt to analyze:
|
| 28 |
{user_prompt}
|
|
|
|
| 35 |
|
| 36 |
analysis = detection_response.choices[0].message.content.strip()
|
| 37 |
|
|
|
|
| 38 |
rewrite_prompt = f"""
|
| 39 |
+
Rewrite the following prompt into a safer version that removes any security risks.
|
| 40 |
+
Output ONLY the rewritten prompt text, without any explanations, notes, or extra words.
|
| 41 |
+
|
| 42 |
Prompt:
|
| 43 |
{user_prompt}
|
| 44 |
"""
|