Spaces:
Sleeping
Sleeping
File size: 1,899 Bytes
f0a6c8a 45364ab f0a6c8a 45364ab f0a6c8a 45364ab acda886 f0a6c8a 45364ab f0a6c8a 45364ab f0a6c8a |
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 |
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()
|