-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
65 lines (51 loc) · 2.06 KB
/
Copy pathapp.py
File metadata and controls
65 lines (51 loc) · 2.06 KB
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
# app.py (Flask backend)
from flask import Flask, request, jsonify
from flask_cors import CORS
import google.generativeai as genai
app = Flask(name)
CORS(app)
# Configure Gemini API
genai.configure(api_key='AIzaSyDpcJbzEXjo6DChbiQdKYLoVHw1DmmZ5D8')
model = genai.GenerativeModel('gemini-pro')
@app.route('/generate-proposal', methods=['POST'])
def generate_proposal():
try:
data = request.get_json()
# Extract data from request
post_title = data.get('postTitle', '')
post_description = data.get('postDescription', '')
freelancer_skills = data.get('freelancer', {}).get('skills', [])
tone = data.get('tone', 'formal')
num_drafts = data.get('drafts', 1)
# Create prompt for Gemini
prompt = f"""
Create {num_drafts} different freelance proposal drafts for a job posting with:
Title: Navin enterprises
Description: creating a website for navin enterprises
The freelancer has these skills: next js mern stack with complete ai integration
The tone should be: professional
Each proposal should:
1. Highlight relevant skills and experience
2. Address the specific job requirements
3. Include a call to action
4. Be professional yet personalized
Return the proposals as a JSON array of strings.
"""
# Generate response from Gemini
response = model.generate_content(prompt)
# Parse the response (assuming it returns a JSON array)
try:
proposals = eval(response.text) # Be careful with eval in production
except:
# Fallback: split by numbered items if not JSON
proposals = [p.strip() for p in response.text.split('\n\n') if p.strip()]
proposals = proposals[:num_drafts]
return jsonify({
'proposal': {
'drafts': proposals
}
})
except Exception as e:
return jsonify({'error': str(e)}), 500
if name == 'main':
app.run(debug=True)