CV_Automation / app.py
aryn25's picture
Update app.py
acda886 verified
raw
history blame
1.9 kB
import gradio as gr
import requests
def generate_cover_letter(resume, job_desc):
prompt = f"""
You are a career coach. Write a tailored, ATS-optimized, professional cover letter based on the resume and job description below.
Resume:
{resume}
Job Description:
{job_desc}
The letter should be concise, engaging, and show why the candidate is a good fit.
"""
try:
response = requests.post(
"https://piapi.ai/api/deepseek",
headers={"Content-Type": "application/json"},
json={
"prompt": prompt,
"system": "You are a helpful assistant.",
"temperature": 0.8
},
timeout=20 # prevent hanging
)
# Check if the response body is valid JSON
if response.status_code == 200:
try:
data = response.json()
return data.get("response", "⚠️ API responded but didn't return any text.")
except Exception as e:
return f"❌ JSON decode failed β€” maybe HTML or empty: {str(e)}\nRaw response:\n{response.text}"
else:
return f"❌ API returned error code {response.status_code}:\n{response.text}"
except requests.exceptions.RequestException as e:
return f"❌ Request failed:\n{str(e)}"
# Gradio UI
gr.Interface(
fn=generate_cover_letter,
inputs=[
gr.Textbox(label="Paste Your Resume", lines=12, placeholder="Paste your resume here..."),
gr.Textbox(label="Paste Job Description", lines=10, placeholder="Paste the job description here...")
],
outputs=gr.Textbox(label="Generated Cover Letter"),
title="AI Cover Letter Generator (DeepSeek LLM)",
description="Paste your resume and job description. Click 'Submit' to generate a personalized, professional cover letter using DeepSeek via PiAPI (no key needed)."
).launch()