Spaces:
Sleeping
Sleeping
import gradio as gr | |
from together import Together | |
import os | |
client = Together(api_key=os.environ.get('TOGETHER_API_KEY')) | |
# Function to create the system prompt based on the selected detector | |
def create_system_prompt(): | |
system_prompt = """You are a expert GMAT profiler who specializes in understanding student profile. You use successful candidate profile as a baseline and compare it with current profile and provide recomendations on the good profile. | |
Analyze the users input and provide guidance on what candidate can do to achieve a target college admission. | |
Provide a detailed response in 500 words. Keep it bulleted. Only provide recommendations if user's profile is not good enough. | |
Always Provide the Response in following format only | |
Format - | |
Analysis : 4-5 lines | |
Recommendation : 4-5 points | |
Possible colleges with current profile: | |
Target college Review and Recommendation: | |
""" | |
return system_prompt | |
# Function to get response from OpenAI API | |
def analyze_chat( gmat_score, gpa, target_college, work_experience, leadership_roles, extracurriculars, personal_statement): | |
system_prompt = create_system_prompt() | |
chat_input = """ | |
User's Profile Data. Assess the following aspects: | |
- GMAT Score: {} | |
- Undergraduate GPA: {} | |
- Target College: {} | |
- Work Experience: {} years | |
- Leadership Roles: {} | |
- Extracurricular Activities: {} | |
- Personal Statement: {} | |
Provide a comprehensive analysis and recommendations. | |
""".format(gmat_score, gpa, target_college, work_experience, leadership_roles, extracurriculars, personal_statement) | |
response = client.chat.completions.create( | |
model="meta-llama/Llama-3.2-3B-Instruct-Turbo", # Change to the OpenAI model you prefer | |
messages=[ | |
{"role": "system", "content": system_prompt}, | |
{"role": "user", "content": chat_input} | |
],) | |
return response.choices[0].message.content.strip() | |
# Gradio interface | |
def gradio_interface(gmat_score, gpa, target_college, work_experience, leadership_roles, extracurriculars, personal_statement): | |
return analyze_chat( gmat_score, gpa, target_college, work_experience, leadership_roles, extracurriculars, personal_statement) | |
# Custom CSS for input restriction | |
custom_css = """ | |
#input-textbox textarea { | |
maxlength: 210; | |
overflow: hidden; | |
resize: none; | |
} | |
""" | |
# Creating the Gradio UI | |
with gr.Blocks(theme=gr.themes.Default(primary_hue=gr.themes.colors.orange, secondary_hue=gr.themes.colors.sky,font=[gr.themes.GoogleFont("Inconsolata"), "Arial", "sans-serif"])) as demo: | |
with gr.Row(): | |
gr.Markdown("## AI GMAT Profiler - Gozo Sensei") | |
with gr.Row(): | |
with gr.Column(scale=2, min_width=300): | |
gmat_score = gr.Number(label="GMAT Score") | |
personal_statement = gr.TextArea(label="Enter your profile details", lines=4,elem_id="input-textbox", | |
info="Please ensure that any Personal Identifiable Information (PII) is removed before submitting the chat.") | |
with gr.Column(scale=2, min_width=300): | |
gpa = gr.Number(label="Undergraduate GPA") | |
work_experience = gr.Number(label="Work Experience (years)") | |
target_college = gr.Textbox(label="Target College") | |
with gr.Column(scale=2, min_width=300): | |
extracurriculars = gr.TextArea(label="Extracurricular Activities",lines=3) | |
leadership_roles = gr.TextArea(label="Leadership Roles",lines=3) | |
with gr.Row(): | |
gr.Markdown("## Response") | |
with gr.Row(): | |
output = gr.Markdown(label="Analysis") | |
#output = gr.TextArea(label="Analysis",info="Disclaimer: The information provided below is generated by AI based on text analytics with limited context. It must not be considered as absolute truth or final judgment.", interactive = False, max_lines=20) | |
with gr.Row(): | |
btn = gr.Button("Analyze") | |
btn.click(fn=gradio_interface, inputs=[gmat_score, gpa, target_college, work_experience, leadership_roles, extracurriculars, personal_statement], outputs=output) | |
# Launch the app | |
demo.launch() | |