Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -32,69 +32,74 @@ def evaluar_prompt(prompt):
|
|
32 |
outputs = model.generate(inputs["input_ids"], max_length=150) # Limit max_length for faster results
|
33 |
analysis = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
34 |
|
35 |
-
# Initialize
|
36 |
-
feedback = f"
|
37 |
-
|
38 |
-
#
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
"asegurando que todos los aspectos del problema sean considerados.\n\n"
|
65 |
-
)
|
66 |
-
|
67 |
-
# Step 4: Practical application
|
68 |
-
feedback += "4. **Aplicaci贸n pr谩ctica:**\n"
|
69 |
-
feedback += (
|
70 |
-
"Podemos revisar un proyecto reciente donde se emprendi贸 una iniciativa similar. Analizando lo que funcion贸 bien e identificando 谩reas de mejora, "
|
71 |
-
"podemos refinar nuestro enfoque para la nueva l铆nea de empaque. La comunicaci贸n clara de los beneficios del empaque y la resoluci贸n de cualquier "
|
72 |
-
"preocupaci贸n funcional ser谩n cr铆ticas para su 茅xito.\n\n"
|
73 |
-
)
|
74 |
-
|
75 |
-
# Step 5: Managing emotions and balancing enthusiasm
|
76 |
-
feedback += "5. **Manejo de emociones y equilibrio del entusiasmo:**\n"
|
77 |
-
feedback += (
|
78 |
-
"Es importante gestionar las emociones durante este proceso. Aunque pueda haber un fuerte entusiasmo por la sostenibilidad dentro del equipo, "
|
79 |
-
"es esencial equilibrar esto con consideraciones de costo y practicidad. Al hacer preguntas abiertas pero directas, desafiar el pensamiento convencional "
|
80 |
-
"y fomentar una mayor discusi贸n, podemos asegurar un enfoque equilibrado y objetivo en el desarrollo del empaque ecol贸gico.\n\n"
|
81 |
-
)
|
82 |
-
|
83 |
-
# Summarize final assessment (Based on the original scoring)
|
84 |
-
calificacion_final = 75 # Assume this as an arbitrary final score for this prompt
|
85 |
-
|
86 |
-
# Final summary
|
87 |
-
if calificacion_final < 51:
|
88 |
-
feedback += f"\n**Conclusi贸n:** El prompt tiene una calificaci贸n de {calificacion_final:.2f}%. Se recomienda realizar mejoras significativas para alinearse con los principios de pensamiento cr铆tico."
|
89 |
else:
|
90 |
-
feedback +=
|
|
|
91 |
|
92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
except Exception as e:
|
95 |
return str(e), "Error"
|
96 |
|
97 |
-
# Gradio Interface with Styles and Layout Inspired by the Example Provided
|
98 |
def interfaz():
|
99 |
with gr.Blocks(css="""
|
100 |
body {
|
@@ -136,27 +141,27 @@ def interfaz():
|
|
136 |
width: 100%;
|
137 |
display: flex;
|
138 |
justify-content: space-between;
|
139 |
-
align-items: center
|
140 |
}
|
141 |
.evaluation-section h2 {
|
142 |
font-size: 36px;
|
143 |
font-weight: bold;
|
144 |
-
margin-bottom: 20px
|
145 |
}
|
146 |
.evaluation-section .left,
|
147 |
.evaluation-section .right {
|
148 |
-
width: 45
|
149 |
}
|
150 |
.evaluation-section .left p,
|
151 |
.evaluation-section .right p {
|
152 |
font-size: 16px;
|
153 |
-
line-height: 1.6
|
154 |
}
|
155 |
.evaluation-section .right {
|
156 |
-
text-align: left
|
157 |
}
|
158 |
.evaluation-section .button-container {
|
159 |
-
margin-top: 20px
|
160 |
}
|
161 |
.evaluation-section .button-container .gr-button {
|
162 |
background-color: #007BFF;
|
@@ -164,10 +169,10 @@ def interfaz():
|
|
164 |
padding: 15px 30px;
|
165 |
font-size: 18px;
|
166 |
border: none;
|
167 |
-
cursor: pointer
|
168 |
}
|
169 |
.evaluation-section .button-container .gr-button:hover {
|
170 |
-
background-color: #0056b3
|
171 |
}
|
172 |
.evaluation-section .gr-textbox,
|
173 |
.evaluation-section .gr-number {
|
@@ -175,12 +180,12 @@ def interfaz():
|
|
175 |
padding: 15px;
|
176 |
font-size: 16px;
|
177 |
margin-top: 10px;
|
178 |
-
box-sizing: border-box
|
179 |
}
|
180 |
""") as demo:
|
181 |
with gr.Row(elem_id="hero-section"):
|
182 |
-
gr.Markdown("<h1>
|
183 |
-
gr.Markdown("<p>
|
184 |
|
185 |
with gr.Row(elem_id="evaluation-section"):
|
186 |
with gr.Column(elem_id="left"):
|
|
|
32 |
outputs = model.generate(inputs["input_ids"], max_length=150) # Limit max_length for faster results
|
33 |
analysis = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
34 |
|
35 |
+
# Initialize feedback
|
36 |
+
feedback = f"An谩lisis del prompt '{prompt}':\n\n"
|
37 |
+
|
38 |
+
# Initialize variables to store detailed advice
|
39 |
+
clarity_advice = ""
|
40 |
+
logic_advice = ""
|
41 |
+
relevance_advice = ""
|
42 |
+
evidence_advice = ""
|
43 |
+
|
44 |
+
# Evaluate clarity
|
45 |
+
if len(prompt.split()) < 5:
|
46 |
+
feedback += "Clarity: The prompt is too brief and may not be clear. Consider adding more details to clarify your request.\n"
|
47 |
+
clarity_advice = "Your prompt is very short, which can lead to ambiguity. Try expanding it to provide more context or specifics."
|
48 |
+
else:
|
49 |
+
feedback += "Clarity: The prompt is clear and well-defined.\n"
|
50 |
+
|
51 |
+
# Evaluate logic
|
52 |
+
if any(word in prompt.lower() for word in ["best", "worst", "only"]):
|
53 |
+
feedback += (
|
54 |
+
"Logic: The prompt uses subjective terms like 'best' which could introduce bias. "
|
55 |
+
"Consider rephrasing to improve objectivity.\n"
|
56 |
+
)
|
57 |
+
logic_advice = f"Words like '{', '.join([w for w in ['best', 'worst', 'only'] if w in prompt.lower()])}' suggest a subjective perspective. Rephrase to focus on objective criteria."
|
58 |
+
else:
|
59 |
+
feedback += "Logic: The prompt is logical and avoids subjective terms.\n"
|
60 |
+
|
61 |
+
# Evaluate relevance
|
62 |
+
if "talk about" in prompt.lower() or "describe" in prompt.lower():
|
63 |
+
feedback += "Relevance: The prompt is relevant and aligned with the request for information.\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
else:
|
65 |
+
feedback += "Relevance: The relevance of the prompt could be improved to better align with the goal. Ensure your prompt directly addresses the core question or objective.\n"
|
66 |
+
relevance_advice = "Your prompt might not directly address the core issue. Ensure that it is directly relevant to the information or action you seek."
|
67 |
|
68 |
+
# Evaluate evidence request
|
69 |
+
if any(word in prompt.lower() for word in ["evidence", "proof", "demonstrate"]):
|
70 |
+
feedback += "Evidence: The prompt requests evidence, which is positive for a well-founded analysis.\n"
|
71 |
+
else:
|
72 |
+
feedback += (
|
73 |
+
"Evidence: The prompt does not explicitly request evidence, which could limit the depth of analysis. "
|
74 |
+
"Consider asking for evidence to support the response.\n"
|
75 |
+
)
|
76 |
+
evidence_advice = "Asking for evidence strengthens your prompt by grounding it in verifiable facts. Consider explicitly requesting evidence or examples."
|
77 |
+
|
78 |
+
# Summary of the evaluation
|
79 |
+
final_score = 65 # Example score
|
80 |
+
|
81 |
+
feedback += f"\n**Final Score:** {final_score}\n"
|
82 |
+
feedback += "\n### Suggestions for Improvement:\n"
|
83 |
+
|
84 |
+
# Provide specific advice based on the issues identified
|
85 |
+
if clarity_advice:
|
86 |
+
feedback += f"\n* **Clarity:** {clarity_advice}"
|
87 |
+
if logic_advice:
|
88 |
+
feedback += f"\n* **Logic:** {logic_advice}"
|
89 |
+
if relevance_advice:
|
90 |
+
feedback += f"\n* **Relevance:** {relevance_advice}"
|
91 |
+
if evidence_advice:
|
92 |
+
feedback += f"\n* **Evidence:** {evidence_advice}"
|
93 |
+
|
94 |
+
# If no advice is necessary, indicate that the prompt is strong
|
95 |
+
if not any([clarity_advice, logic_advice, relevance_advice, evidence_advice]):
|
96 |
+
feedback += "\nYour prompt is well-constructed with no major areas for improvement."
|
97 |
+
|
98 |
+
return feedback, final_score
|
99 |
|
100 |
except Exception as e:
|
101 |
return str(e), "Error"
|
102 |
|
|
|
103 |
def interfaz():
|
104 |
with gr.Blocks(css="""
|
105 |
body {
|
|
|
141 |
width: 100%;
|
142 |
display: flex;
|
143 |
justify-content: space-between;
|
144 |
+
align-items: center.
|
145 |
}
|
146 |
.evaluation-section h2 {
|
147 |
font-size: 36px;
|
148 |
font-weight: bold;
|
149 |
+
margin-bottom: 20px.
|
150 |
}
|
151 |
.evaluation-section .left,
|
152 |
.evaluation-section .right {
|
153 |
+
width: 45%.
|
154 |
}
|
155 |
.evaluation-section .left p,
|
156 |
.evaluation-section .right p {
|
157 |
font-size: 16px;
|
158 |
+
line-height: 1.6.
|
159 |
}
|
160 |
.evaluation-section .right {
|
161 |
+
text-align: left.
|
162 |
}
|
163 |
.evaluation-section .button-container {
|
164 |
+
margin-top: 20px.
|
165 |
}
|
166 |
.evaluation-section .button-container .gr-button {
|
167 |
background-color: #007BFF;
|
|
|
169 |
padding: 15px 30px;
|
170 |
font-size: 18px;
|
171 |
border: none;
|
172 |
+
cursor: pointer.
|
173 |
}
|
174 |
.evaluation-section .button-container .gr-button:hover {
|
175 |
+
background-color: #0056b3.
|
176 |
}
|
177 |
.evaluation-section .gr-textbox,
|
178 |
.evaluation-section .gr-number {
|
|
|
180 |
padding: 15px;
|
181 |
font-size: 16px;
|
182 |
margin-top: 10px;
|
183 |
+
box-sizing: border-box.
|
184 |
}
|
185 |
""") as demo:
|
186 |
with gr.Row(elem_id="hero-section"):
|
187 |
+
gr.Markdown("<h1>Alfred</h1>", elem_classes="hero-section")
|
188 |
+
gr.Markdown("<p>Research & Development phase.</p>", elem_classes="hero-section")
|
189 |
|
190 |
with gr.Row(elem_id="evaluation-section"):
|
191 |
with gr.Column(elem_id="left"):
|