Spaces:
Sleeping
Sleeping
File size: 7,520 Bytes
dd3178b 2e79ccc dd3178b 2e79ccc 09f4295 42b4b03 09f4295 42b4b03 09f4295 42b4b03 09f4295 42b4b03 09f4295 42b4b03 09f4295 42b4b03 09f4295 42b4b03 09f4295 42b4b03 09f4295 42b4b03 09f4295 42b4b03 e2bc3f2 09f4295 e2bc3f2 d25ebb3 42b4b03 09f4295 42b4b03 09f4295 42b4b03 09f4295 42b4b03 09f4295 42b4b03 e2bc3f2 09f4295 e2bc3f2 2e79ccc dd3178b 364b7da | 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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | from fastapi import FastAPI, Request
import gradio as gr
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
# Add CORS middleware to allow requests from Make.com or Postman
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Allow all origins (you can restrict this in production)
allow_methods=["POST"],
allow_headers=["*"],
)
def bulletify(text_string, prefix="- "):
"""
Takes a comma-separated string (e.g. "Goal1, Goal2")
and returns multiple lines with the given prefix:
"- Goal1<br>- Goal2"
If text_string is empty, returns an empty string.
"""
items = [x.strip() for x in text_string.split(",") if x.strip()]
if not items:
return ""
return "<br>".join(f"{prefix}{item}" for item in items)
def numbered_listify(text_string):
"""
Takes a comma-separated string (e.g. "Strength1, Strength2")
and returns a numbered list:
"1. Strength1<br>2. Strength2"
"""
items = [x.strip() for x in text_string.split(",") if x.strip()]
if not items:
return ""
lines = []
for i, item in enumerate(items, start=1):
lines.append(f"{i}. {item}")
return "<br>".join(lines)
def generate_cv(
email,
date_of_birth,
mbti,
sustainable_dev_goals, # e.g. "8. Decent Work, 9. Industry Innovation"
via_strengths, # e.g. "Creativity, Curiosity, Leadership, ..."
disc_d,
disc_i,
disc_s,
disc_c,
big5_openness, # a.k.a. "Big5 - Openness" or "Big5 - Extroversion," etc.
big5_conscientiousness,
big5_extraversion,
big5_agreeableness,
big5_emotional_stability,
past_project,
influences,
main_passions,
preferred_location,
ideal_work_environment,
productive_time,
partner_qualities,
vision
):
"""
Generates a text-based CV (Markdown tables) with bullet lists for multi-select fields.
NOTE: Make.com should combine multi-select choices into comma-separated strings
before sending here.
"""
# Convert multi-select fields into bullet/numbered lines:
sdg_bullets = bulletify(sustainable_dev_goals) # each item -> separate bullet
via_bullets = numbered_listify(via_strengths) # each item -> separate numbered line
productive_time_bullets = bulletify(productive_time) # if multiple time blocks
main_passions_bullets = bulletify(main_passions) # optional if multi-select
cv_text = f"""
# CV Template
## Essential Information
| Field | Details |
|-----------------------------------|--------------------------------------------------------------|
| **Email Address** | {email} |
| **Date of Birth** | {date_of_birth} |
| **16 Personalities (MBTI)** | {mbti} |
| **Sustainable Development Goals** | {sdg_bullets if sdg_bullets else "N/A"} |
| **VIA Strengths (Top 5)** | {via_bullets if via_bullets else "N/A"} |
## Personality Profile
| Field | Details |
|---------------------|-----------------------------------------------------------------------------------------------------|
| **DISC (D, I, S, C)** | D: {disc_d}%<br>I: {disc_i}%<br>S: {disc_s}%<br>C: {disc_c}% |
| **Big Five (OCEAN)** | Openness: {big5_openness}%<br>Conscientiousness: {big5_conscientiousness}%<br>Extraversion: {big5_extraversion}%<br>Agreeableness: {big5_agreeableness}%<br>Emotional Stability: {big5_emotional_stability}% |
## Interests & Passions
| Field | Details |
|------------------------------------------------------|----------------------------------------------|
| **Past Project or Workplace You Loved (Why)** | {past_project} |
| **People, Books, Courses, or Resources That Shaped You (Why)** | {influences} |
| **Main Passions & Topics of Interest** | {main_passions_bullets if main_passions_bullets else main_passions} |
## Collaboration Preferences
| Field | Details |
|---------------------------------------------------|-----------------------------------------------------|
| **Preferred Country & Town for Meetups** | {preferred_location} |
| **Ideal Work Environment** | {ideal_work_environment} |
| **Most Productive Time of Day/Night** | {productive_time_bullets if productive_time_bullets else productive_time} |
| **Qualities in an Ideal Partner (Professional/Personal)** | {partner_qualities} |
| **Vision for Future Collaboration or Partnership** | {vision} |
"""
return cv_text.strip()
# GRADIO INTERFACE
demo = gr.Interface(
fn=generate_cv,
inputs=[
"text", # email
"text", # date_of_birth
"text", # mbti
"text", # sustainable_dev_goals
"text", # via_strengths
"text", # disc_d
"text", # disc_i
"text", # disc_s
"text", # disc_c
"text", # big5_openness
"text", # big5_conscientiousness
"text", # big5_extraversion
"text", # big5_agreeableness
"text", # big5_emotional_stability
"text", # past_project
"text", # influences
"text", # main_passions
"text", # preferred_location
"text", # ideal_work_environment
"text", # productive_time
"text", # partner_qualities
"text" # vision
],
outputs="text",
title="CV Template with Markdown Tables + Bullets"
)
# FastAPI endpoint for POST requests
@app.post("/run/predict")
async def predict(request: Request):
data = await request.json()
cv_output = generate_cv(
email=data.get("email"),
date_of_birth=data.get("date_of_birth"),
mbti=data.get("mbti"),
sustainable_dev_goals=data.get("sustainable_dev_goals"),
via_strengths=data.get("via_strengths"),
disc_d=data.get("disc_d"),
disc_i=data.get("disc_i"),
disc_s=data.get("disc_s"),
disc_c=data.get("disc_c"),
big5_openness=data.get("big5_openness"),
big5_conscientiousness=data.get("big5_conscientiousness"),
big5_extraversion=data.get("big5_extraversion"),
big5_agreeableness=data.get("big5_agreeableness"),
big5_emotional_stability=data.get("big5_emotional_stability"),
past_project=data.get("past_project"),
influences=data.get("influences"),
main_passions=data.get("main_passions"),
preferred_location=data.get("preferred_location"),
ideal_work_environment=data.get("ideal_work_environment"),
productive_time=data.get("productive_time"),
partner_qualities=data.get("partner_qualities"),
vision=data.get("vision")
)
return {"cv_output": cv_output}
# Launch Gradio and FastAPI
demo.launch(server_name="0.0.0.0", server_port=7860, share=True) |