aika42 commited on
Commit
b553816
·
verified ·
1 Parent(s): ce0c6d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -11
app.py CHANGED
@@ -1,5 +1,3 @@
1
- # 👮 PromptPolice MVP - Streamlit App with Mistral Backend (JSON Output)
2
-
3
  import streamlit as st
4
  import requests
5
  import json
@@ -12,22 +10,17 @@ HEADERS = {
12
  "Content-Type": "application/json"
13
  }
14
 
 
15
  PROMPT_TEMPLATE = """
16
  You are a prompt evaluation assistant. Evaluate the following user prompt in JSON format using the structure provided below.
17
-
18
  Prompt:
19
-
20
- """
21
  {user_prompt}
22
- """
23
-
24
  Evaluate based on the following criteria:
25
  - Clarity (1-5)
26
  - Context (1-5)
27
  - Specificity (1-5)
28
  - Intent (1-5)
29
  Also include a suggestion for improving the prompt.
30
-
31
  Respond ONLY in this JSON format:
32
  {
33
  "prompt": "...",
@@ -42,7 +35,7 @@ Respond ONLY in this JSON format:
42
  """
43
 
44
  def evaluate_prompt(user_prompt):
45
- # Format the input prompt
46
  formatted_prompt = PROMPT_TEMPLATE.format(user_prompt=user_prompt)
47
 
48
  payload = {
@@ -57,7 +50,7 @@ def evaluate_prompt(user_prompt):
57
 
58
  try:
59
  # Send request to DeepSeek API
60
- response = requests.post(API_URL, headers=HEADERS, json=payload)
61
  response.raise_for_status()
62
 
63
  result = response.json()
@@ -91,4 +84,4 @@ if st.button("Evaluate Prompt") and user_prompt:
91
  if st.button("💾 Save to Dataset"):
92
  with open("crowdsourced_prompts.jsonl", "a", encoding="utf-8") as f:
93
  f.write(json.dumps(evaluation_result) + "\n")
94
- st.success("Prompt evaluation saved!")
 
 
 
1
  import streamlit as st
2
  import requests
3
  import json
 
10
  "Content-Type": "application/json"
11
  }
12
 
13
+ # Correctly format the prompt string with {user_prompt} placeholder inside the string
14
  PROMPT_TEMPLATE = """
15
  You are a prompt evaluation assistant. Evaluate the following user prompt in JSON format using the structure provided below.
 
16
  Prompt:
 
 
17
  {user_prompt}
 
 
18
  Evaluate based on the following criteria:
19
  - Clarity (1-5)
20
  - Context (1-5)
21
  - Specificity (1-5)
22
  - Intent (1-5)
23
  Also include a suggestion for improving the prompt.
 
24
  Respond ONLY in this JSON format:
25
  {
26
  "prompt": "...",
 
35
  """
36
 
37
  def evaluate_prompt(user_prompt):
38
+ # Format the input prompt by inserting the user_prompt dynamically
39
  formatted_prompt = PROMPT_TEMPLATE.format(user_prompt=user_prompt)
40
 
41
  payload = {
 
50
 
51
  try:
52
  # Send request to DeepSeek API
53
+ response = requests.post(HF_API_URL, headers=HEADERS, json=payload)
54
  response.raise_for_status()
55
 
56
  result = response.json()
 
84
  if st.button("💾 Save to Dataset"):
85
  with open("crowdsourced_prompts.jsonl", "a", encoding="utf-8") as f:
86
  f.write(json.dumps(evaluation_result) + "\n")
87
+ st.success("Prompt evaluation saved!")