Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -40,25 +40,37 @@ Respond ONLY in this JSON format:
|
|
| 40 |
"""
|
| 41 |
|
| 42 |
def evaluate_prompt(user_prompt):
|
|
|
|
|
|
|
|
|
|
| 43 |
payload = {
|
| 44 |
-
"
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
}
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
| 61 |
return result
|
|
|
|
|
|
|
| 62 |
|
| 63 |
# --- Streamlit UI ---
|
| 64 |
st.set_page_config(page_title="👮 PromptPolice", layout="centered")
|
|
@@ -67,7 +79,7 @@ st.title("👮 PromptPolice: Prompt Evaluator")
|
|
| 67 |
user_prompt = st.text_area("Paste your AI prompt here:", height=200)
|
| 68 |
|
| 69 |
if st.button("Evaluate Prompt") and user_prompt:
|
| 70 |
-
with st.spinner("Evaluating your prompt with
|
| 71 |
evaluation_result = evaluate_prompt(user_prompt)
|
| 72 |
|
| 73 |
st.subheader("Evaluation Result (JSON):")
|
|
|
|
| 40 |
"""
|
| 41 |
|
| 42 |
def evaluate_prompt(user_prompt):
|
| 43 |
+
# Format the input prompt
|
| 44 |
+
formatted_prompt = PROMPT_TEMPLATE.format(user_prompt=user_prompt)
|
| 45 |
+
|
| 46 |
payload = {
|
| 47 |
+
"messages": [
|
| 48 |
+
{
|
| 49 |
+
"role": "user",
|
| 50 |
+
"content": formatted_prompt
|
| 51 |
+
}
|
| 52 |
+
],
|
| 53 |
+
"model": "deepseek/deepseek-v3-0324"
|
| 54 |
}
|
| 55 |
|
| 56 |
+
try:
|
| 57 |
+
# Send request to DeepSeek API
|
| 58 |
+
response = requests.post(API_URL, headers=HEADERS, json=payload)
|
| 59 |
+
response.raise_for_status()
|
| 60 |
+
|
| 61 |
+
result = response.json()
|
| 62 |
+
|
| 63 |
+
# Extract JSON formatted evaluation
|
| 64 |
+
if isinstance(result, dict) and "choices" in result:
|
| 65 |
+
raw_text = result["choices"][0]["message"]["content"]
|
| 66 |
+
try:
|
| 67 |
+
json_part = raw_text[raw_text.index("{"):]
|
| 68 |
+
return json.loads(json_part)
|
| 69 |
+
except (ValueError, json.JSONDecodeError) as e:
|
| 70 |
+
return {"error": f"Failed to parse model output: {str(e)}"}
|
| 71 |
return result
|
| 72 |
+
except requests.exceptions.RequestException as e:
|
| 73 |
+
return {"error": f"API request failed: {str(e)}"}
|
| 74 |
|
| 75 |
# --- Streamlit UI ---
|
| 76 |
st.set_page_config(page_title="👮 PromptPolice", layout="centered")
|
|
|
|
| 79 |
user_prompt = st.text_area("Paste your AI prompt here:", height=200)
|
| 80 |
|
| 81 |
if st.button("Evaluate Prompt") and user_prompt:
|
| 82 |
+
with st.spinner("Evaluating your prompt with DeepSeek..."):
|
| 83 |
evaluation_result = evaluate_prompt(user_prompt)
|
| 84 |
|
| 85 |
st.subheader("Evaluation Result (JSON):")
|