Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
import gradio as gr | |
import os | |
import re | |
from groq import Groq | |
groq_client = Groq(api_key=os.environ.get("GROQ_API_KEY")) | |
def call_groq_api(specific, measurable, achievable, relevant, time_bound): | |
prompt = f""" | |
Act as a world-class professional consultant and SMART Goal writer. | |
Generate three distinct, well-written SMART goal statements in complete sentences by taking into account the SMART criteria provided. | |
Specific (S): {specific} | |
Measurable (M): {measurable} | |
Achievable (A): {achievable} | |
Relevant (R): {relevant} | |
Time-bound (T): {time_bound} | |
Format each option as a complete professional high-quality SMART goal in one sentence and number them as Option 1, Option 2, and Option 3. | |
""" | |
chat_completion = groq_client.chat.completions.create( | |
messages=[{"role": "user", "content": prompt}], | |
model="llama3-70b-8192", | |
) | |
if chat_completion.choices: | |
generated_text = chat_completion.choices[0].message.content | |
print("LLM Response:", generated_text) | |
options = re.split(r'\n\s*\n', generated_text) | |
formatted_options = [opt for opt in options if opt.strip().startswith('**Option')] | |
return '\n\n'.join(formatted_options) | |
else: | |
print("Error: No response from Groq API or API returned an unexpected format.") | |
return "Error: No response from Groq API." | |
smart_examples = { | |
"specific": [ | |
"Increase quarterly sales revenue by focusing on upsells and expanding into the health segment", | |
"Raise customer satisfaction scores using targeted service improvements", | |
"Grow team productivity by implementing a new collaborative project management tool", | |
"Complete an advanced coding course on Coursera and contribute to a live project", | |
"Attend five key industry networking events to forge at least ten new strategic relationships" | |
], | |
"measurable": [ | |
"Achieve a 15 percent increase in sales compared to the previous quarter", | |
"Improve customer satisfaction scores by 15 points on our satisfaction survey", | |
"Complete the Coursera coding course with a final project review score of 80 percent or higher", | |
"Connect with at least ten new potential partners or clients at each networking event", | |
"Increase the number of successful project deliveries by 20% within the next fiscal year" | |
], | |
"achievable": [ | |
"Targeting existing customers with a proven 20 percent interest in health and wellness products", | |
"Introducing a customer feedback loop and response team within the next month", | |
"Leveraging existing resources and the new tool to streamline task management", | |
"Dedicating 5 hours per week to online learning and project work", | |
"Selecting events based on past success rates for networking and lead generation" | |
], | |
"relevant": [ | |
"Aligning with the strategic goal to penetrate the health and wellness market", | |
"Directly addressing a key pain point identified in the last customer satisfaction audit", | |
"Supporting the company-wide initiative to enhance teamwork and efficiency", | |
"Complementing current role responsibilities with an upgraded skill set", | |
"Expanding business contacts in line with the growth strategy for the coming year" | |
], | |
"time_bound": [ | |
"By the end of the second quarter", | |
"Within the next six months to coincide with the next customer review cycle", | |
"By the end of the current fiscal year", | |
"Within the next three months, in time to apply skills to Q4 projects", | |
"Over the next six months, strategically spaced to maintain momentum" | |
] | |
} | |
def smart_goal_interface(specific, measurable, achievable, relevant, time_bound): | |
return call_groq_api(specific, measurable, achievable, relevant, time_bound) | |
interface = gr.Interface( | |
fn=smart_goal_interface, | |
inputs=[ | |
gr.Dropdown(label="Specific (S)", allow_custom_value=True, choices=smart_examples['specific'], info="Select from an example or type out your specific goal"), | |
gr.Dropdown(label="Measurable (M)", allow_custom_value=True, choices=smart_examples['measurable'], info="Select from an example or type out how you will measure the goal"), | |
gr.Dropdown(label="Achievable (A)", allow_custom_value=True, choices=smart_examples['achievable'], info="Select from an example or type out how the goal is challenging yet achievable"), | |
gr.Dropdown(label="Relevant (R)", allow_custom_value=True, choices=smart_examples['relevant'], info="Select from an example or type out why this goal is important"), | |
gr.Dropdown(label="Time-bound (T)", allow_custom_value=True, choices=smart_examples['time_bound'], info="Select from an example or type out enter the deadline for the goal") | |
], | |
outputs=[ | |
gr.Textbox(label="Generated SMART Goals", lines=10, placeholder="Generated content will appear here...") | |
], | |
title="SMART Goals Builder powered by Llama3 and Groq", | |
description="Fill out each field to generate SMART goals." | |
) | |
if __name__ == "__main__": | |
interface.launch() | |