Spaces:
Runtime error
Runtime error
File size: 5,950 Bytes
8d07da7 ee1ccda 8d07da7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
import os
import requests
import gradio as gr
API_URL = "https://qxe01xvjbi60tf32.us-east-1.aws.endpoints.huggingface.cloud"
headers = {
"Accept": "application/json",
"Authorization": f"Bearer {os.environ['HF_ACCESS_TOKEN']}",
"Content-Type": "application/json",
}
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
TASK_DESCRIPTION = """
###Task Description:
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.
1. Write a detailed feedback that assess the quality of the response strictly based on the given score rubric, not evaluating in general.
2. After writing a feedback, write a score that is an integer between 1 and 5. You should refer to the score rubric.
3. The output format should look as follows: "Feedback: (write a feedback for criteria) [RESULT] (an integer number between 1 and 5)"
4. Please do not generate any other opening, closing, and explanations.
"""
EXAMPLE_INSTRUCTION = "How can I improve my time management skills?"
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:
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.
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.
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.
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.
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.
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.
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.
By implementing these tips, you can improve your time management skills and become more productive and efficient."""
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.
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.
Avoid multitasking as it can lead to mistakes and inefficiency. Instead, focus on one task at a time until it's complete.
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."""
EXAMPLE_RUBRIC_QUESTION = "Does the response provide detailed and actionable steps grounded on real-world scenarios?"
EXAMPLE_SCORE_1 = (
"The response lacks detail and provides no actionable steps or real-world context."
)
EXAMPLE_SCORE_2 = "The response provides limited detail and few actionable steps, with minimal real-world grounding."
EXAMPLE_SCORE_3 = "The response has some detailed and actionable steps, though not all are grounded in real-world scenarios."
EXAMPLE_SCORE_4 = "The response is detailed with mostly actionable steps, and the majority are grounded in real-world scenarios."
EXAMPLE_SCORE_5 = "The response is comprehensive, offering detailed and actionable steps, all of which are firmly grounded on real-world scenarios."
def generate_feedback(
instruction,
response,
reference_response,
rubric_question,
score_1,
score_2,
score_3,
score_4,
score_5,
):
input = f"""{TASK_DESCRIPTION}
###The instruction to evaluate:
{instruction}
###Response to evaluate:
{response}
###Reference Answer (Score 5):
{reference_response}
###Score Rubrics:
[{rubric_question}]
Score 1: {score_1}
Score 2: {score_2}
Score 3: {score_3}
Score 4: {score_4}
Score 5: {score_5}
###Feedback:
"""
output = query({"inputs": input, "parameters": {}})
feedback = output[0]["generated_text"].split("###Feedback:")[-1].strip()
try:
text, score = feedback.split("[RESULT]")
score = int(score)
except:
text = feedback
score = -1
return text, score
demo = gr.Interface(
fn=generate_feedback,
inputs=["text", "text", "text", "text", "text", "text", "text", "text", "text"],
outputs=[gr.Textbox(label="Feedback Text"), gr.Number(label="Score")],
examples=[
[
EXAMPLE_INSTRUCTION,
EXAMPLE_RESPONSE,
EXAMPLE_REFERENCE_RESPONSE,
EXAMPLE_RUBRIC_QUESTION,
EXAMPLE_SCORE_1,
EXAMPLE_SCORE_2,
EXAMPLE_SCORE_3,
EXAMPLE_SCORE_4,
EXAMPLE_SCORE_5,
]
],
)
demo.launch(share=True) |