File size: 3,031 Bytes
934532f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import json
import requests
import gradio as gr

# ==============================
# GROQ API CONFIG
# ==============================

GROQ_API_KEY = os.environ.get("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")
GROQ_URL = "https://api.groq.com/openai/v1/chat/completions"

MODEL = "llama3-70b-8192"  # fast + powerful

# ==============================
# PROPOSAL GENERATION FUNCTION
# ==============================

def generate_proposal(job_description, skills, experience_level, tone):

    if not GROQ_API_KEY:
        return "Error: GROQ_API_KEY not found in environment variables."

    prompt = f"""
You are a top 1% freelancer who writes high-converting proposals.

Your task:
Generate a professional, persuasive, personalized freelance proposal.

Job Description:
{job_description}

Freelancer Skills:
{skills}

Experience Level:
{experience_level}

Tone:
{tone}

Return ONLY valid JSON in this format:

{{
  "hook": "",
  "proposal_body": "",
  "pricing_suggestion": "",
  "follow_up_message": ""
}}
"""

    headers = {
        "Authorization": f"Bearer {GROQ_API_KEY}",
        "Content-Type": "application/json"
    }

    payload = {
        "model": MODEL,
        "messages": [
            {"role": "system", "content": "You write winning freelance proposals."},
            {"role": "user", "content": prompt}
        ],
        "temperature": 0.7
    }

    try:
        response = requests.post(GROQ_URL, headers=headers, json=payload)
        result = response.json()

        content = result["choices"][0]["message"]["content"]

        # Clean JSON if wrapped in code block
        if content.startswith("```"):
            content = content.split("```")[1]

        data = json.loads(content)

        final_output = f"""
πŸ”₯ HOOK:
{data['hook']}

πŸ“„ PROPOSAL:
{data['proposal_body']}

πŸ’° PRICING SUGGESTION:
{data['pricing_suggestion']}

πŸ“© FOLLOW-UP MESSAGE:
{data['follow_up_message']}
"""

        return final_output

    except Exception as e:
        return f"Error generating proposal: {str(e)}"


# ==============================
# GRADIO UI
# ==============================

with gr.Blocks(title="AI Proposal Generator for Freelancers") as app:

    gr.Markdown("## πŸš€ AI Proposal Generator")
    gr.Markdown("Generate high-converting freelance proposals instantly.")

    job_description = gr.Textbox(label="Job Description", lines=8)
    skills = gr.Textbox(label="Your Skills", lines=5)

    experience_level = gr.Dropdown(
        ["Beginner", "Intermediate", "Expert"],
        label="Experience Level",
        value="Intermediate"
    )

    tone = gr.Dropdown(
        ["Professional", "Confident", "Friendly", "Persuasive"],
        label="Tone",
        value="Professional"
    )

    generate_btn = gr.Button("Generate Proposal")

    output = gr.Textbox(label="Generated Proposal", lines=20)

    generate_btn.click(
        generate_proposal,
        inputs=[job_description, skills, experience_level, tone],
        outputs=output
    )

app.launch()