Spaces:
Runtime error
Runtime error
michael-hhai
commited on
Commit
•
8d07da7
1
Parent(s):
30ffad9
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import requests
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
API_URL = "https://qxe01xvjbi60tf32.us-east-1.aws.endpoints.huggingface.cloud"
|
6 |
+
headers = {
|
7 |
+
"Accept": "application/json",
|
8 |
+
"Authorization": f"Bearer {os.environ["HF_ACCESS_TOKEN"]}",
|
9 |
+
"Content-Type": "application/json",
|
10 |
+
}
|
11 |
+
|
12 |
+
|
13 |
+
def query(payload):
|
14 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
15 |
+
return response.json()
|
16 |
+
|
17 |
+
|
18 |
+
TASK_DESCRIPTION = """
|
19 |
+
###Task Description:
|
20 |
+
An instruction (might include an Input inside it), a response to evaluate, a reference answer that gets a score of 5, and a score rubric representing a evaluation criteria are given.
|
21 |
+
1. Write a detailed feedback that assess the quality of the response strictly based on the given score rubric, not evaluating in general.
|
22 |
+
2. After writing a feedback, write a score that is an integer between 1 and 5. You should refer to the score rubric.
|
23 |
+
3. The output format should look as follows: "Feedback: (write a feedback for criteria) [RESULT] (an integer number between 1 and 5)"
|
24 |
+
4. Please do not generate any other opening, closing, and explanations.
|
25 |
+
"""
|
26 |
+
|
27 |
+
EXAMPLE_INSTRUCTION = "How can I improve my time management skills?"
|
28 |
+
EXAMPLE_RESPONSE = """Improving your time management skills can help you to be more productive, reduce stress, and achieve your goals. Here are some tips to help you improve your time management skills:
|
29 |
+
|
30 |
+
1. Prioritize your tasks: Make a to-do list at the beginning of each day and prioritize the most important tasks. This will help you to focus on what's most important and avoid wasting time on low-priority tasks.
|
31 |
+
2. Use a calendar or planner: Use a calendar or planner to schedule your tasks and appointments. This will help you to stay organized and ensure that you have enough time for everything you need to do.
|
32 |
+
3. Set goals: Set realistic goals for yourself and break them down into smaller, manageable tasks. This will help you to stay focused and motivated.
|
33 |
+
4. Eliminate distractions: Identify the things that distract you the most, such as social media or email notifications, and find ways to eliminate them. This could be as simple as turning off your phone or logging out of social media during work hours.
|
34 |
+
5. Take breaks: Taking regular breaks can help you to stay focused and avoid burnout. Take a few minutes every hour to stretch, go for a walk, or do something that you enjoy.
|
35 |
+
6. Learn to say no: Don't overcommit yourself by taking on too many tasks or responsibilities. Learn to say no to requests that don't align with your goals or values.
|
36 |
+
7. Review and adjust: Regularly review your schedule and priorities to ensure that you are making the most of your time. Adjust your plans as needed to accommodate changes in your workload or personal life.
|
37 |
+
|
38 |
+
By implementing these tips, you can improve your time management skills and become more productive and efficient."""
|
39 |
+
EXAMPLE_REFERENCE_RESPONSE = """To improve your time management skills, start by setting clear goals. Understand what you want to achieve and by when. This will give you a roadmap to follow. Next, prioritize your tasks based on their importance and urgency. Use tools like the Eisenhower Box to help you with this. Break down larger tasks into smaller, manageable parts to prevent feeling overwhelmed.
|
40 |
+
|
41 |
+
Establish a routine and stick to it. This could be a daily, weekly, or monthly routine depending on your goals. Use tools like calendars, planners, or apps like Google Calendar to schedule your tasks and set reminders.
|
42 |
+
|
43 |
+
Avoid multitasking as it can lead to mistakes and inefficiency. Instead, focus on one task at a time until it's complete.
|
44 |
+
|
45 |
+
Finally, take regular breaks to avoid burnout. Techniques like the Pomodoro Technique, where you work for 25 minutes then take a 5-minute break, can be very effective. Remember, managing your time effectively also involves taking care of your mental health."""
|
46 |
+
EXAMPLE_RUBRIC_QUESTION = "Does the response provide detailed and actionable steps grounded on real-world scenarios?"
|
47 |
+
EXAMPLE_SCORE_1 = (
|
48 |
+
"The response lacks detail and provides no actionable steps or real-world context."
|
49 |
+
)
|
50 |
+
EXAMPLE_SCORE_2 = "The response provides limited detail and few actionable steps, with minimal real-world grounding."
|
51 |
+
EXAMPLE_SCORE_3 = "The response has some detailed and actionable steps, though not all are grounded in real-world scenarios."
|
52 |
+
EXAMPLE_SCORE_4 = "The response is detailed with mostly actionable steps, and the majority are grounded in real-world scenarios."
|
53 |
+
EXAMPLE_SCORE_5 = "The response is comprehensive, offering detailed and actionable steps, all of which are firmly grounded on real-world scenarios."
|
54 |
+
|
55 |
+
|
56 |
+
def generate_feedback(
|
57 |
+
instruction,
|
58 |
+
response,
|
59 |
+
reference_response,
|
60 |
+
rubric_question,
|
61 |
+
score_1,
|
62 |
+
score_2,
|
63 |
+
score_3,
|
64 |
+
score_4,
|
65 |
+
score_5,
|
66 |
+
):
|
67 |
+
input = f"""{TASK_DESCRIPTION}
|
68 |
+
|
69 |
+
###The instruction to evaluate:
|
70 |
+
{instruction}
|
71 |
+
|
72 |
+
###Response to evaluate:
|
73 |
+
{response}
|
74 |
+
|
75 |
+
###Reference Answer (Score 5):
|
76 |
+
{reference_response}
|
77 |
+
|
78 |
+
###Score Rubrics:
|
79 |
+
[{rubric_question}]
|
80 |
+
Score 1: {score_1}
|
81 |
+
Score 2: {score_2}
|
82 |
+
Score 3: {score_3}
|
83 |
+
Score 4: {score_4}
|
84 |
+
Score 5: {score_5}
|
85 |
+
|
86 |
+
###Feedback:
|
87 |
+
"""
|
88 |
+
|
89 |
+
output = query({"inputs": input, "parameters": {}})
|
90 |
+
|
91 |
+
feedback = output[0]["generated_text"].split("###Feedback:")[-1].strip()
|
92 |
+
try:
|
93 |
+
text, score = feedback.split("[RESULT]")
|
94 |
+
score = int(score)
|
95 |
+
except:
|
96 |
+
text = feedback
|
97 |
+
score = -1
|
98 |
+
return text, score
|
99 |
+
|
100 |
+
|
101 |
+
demo = gr.Interface(
|
102 |
+
fn=generate_feedback,
|
103 |
+
inputs=["text", "text", "text", "text", "text", "text", "text", "text", "text"],
|
104 |
+
outputs=[gr.Textbox(label="Feedback Text"), gr.Number(label="Score")],
|
105 |
+
examples=[
|
106 |
+
[
|
107 |
+
EXAMPLE_INSTRUCTION,
|
108 |
+
EXAMPLE_RESPONSE,
|
109 |
+
EXAMPLE_REFERENCE_RESPONSE,
|
110 |
+
EXAMPLE_RUBRIC_QUESTION,
|
111 |
+
EXAMPLE_SCORE_1,
|
112 |
+
EXAMPLE_SCORE_2,
|
113 |
+
EXAMPLE_SCORE_3,
|
114 |
+
EXAMPLE_SCORE_4,
|
115 |
+
EXAMPLE_SCORE_5,
|
116 |
+
]
|
117 |
+
],
|
118 |
+
)
|
119 |
+
demo.launch(share=True)
|