-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempCodeRunnerFile.py
More file actions
106 lines (78 loc) · 3.69 KB
/
tempCodeRunnerFile.py
File metadata and controls
106 lines (78 loc) · 3.69 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
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
from flask import Flask, request, render_template, jsonify
import requests, os
from dotenv import load_dotenv
load_dotenv()
app = Flask(__name__)
API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.3"
HEADERS = {"Authorization": f"Bearer {os.getenv('HUGGINGFACE_API_KEY')}"}
@app.route("/")
def home():
return render_template("index.html")
@app.route("/promt", methods=["GET"])
def promt():
return render_template("promt.html")
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/contact')
def contact():
return render_template('contact.html')
@app.route('/learnmore')
def learn_more():
return render_template('learnmore.html')
@app.route("/advisor", methods=["POST"])
def advisor():
try:
data = request.json
user_input = data.get('input')
if not user_input:
return jsonify({'error': 'No input provided'}), 400
# Generate growth advice or respond to user question
if "growth strategies" in user_input.lower():
prompt = (
"You are an expert startup growth advisor. Provide 5-6 unique, trending, and actionable strategies "
"for startups in the tech, AI, and SaaS industries. The strategies should be practical and current."
)
else:
prompt = (
"You are a professional startup advisor who provides clear, practical guidance "
"for launching, growing, and managing businesses, with a focus on tech, gaming, "
"and AI sectors. Provide responses directly without repeating the user's question. "
"Ensure your response is thorough, detailed, and step-by-step when applicable.\n\n"
f"Question: {user_input}\n\nAnswer:"
)
response = requests.post(API_URL, headers=HEADERS, json={"inputs": prompt})
if response.status_code == 200:
result = response.json()
if isinstance(result, list) and len(result) > 0:
full_response = result[0].get("generated_text", "").strip()
response_text = full_response.split("Answer:", 1)[-1].strip() if "Answer:" in full_response else full_response
return jsonify({"response": response_text})
return jsonify({"error": response.text}), response.status_code
except Exception as e:
return jsonify({"error": str(e)}), 500
@app.route("/validate", methods=["POST"])
def validate():
try:
data = request.json
user_input = data.get('input')
if not user_input:
return jsonify({'error': 'No input provided'}), 400
formatted_input = (
"You are an expert in startup evaluations. Analyze the following startup idea by "
"assessing its market potential, strengths, weaknesses, and growth opportunities. "
"Provide only the analysis in paragraph form without repeating the input idea.\n\n"
f"Startup Idea: {user_input}\n\nAnalysis:"
)
response = requests.post(API_URL, headers=HEADERS, json={"inputs": formatted_input})
if response.status_code == 200:
result = response.json()
if isinstance(result, list) and len(result) > 0:
full_response = result[0].get('generated_text', '').strip()
ai_response = full_response.split("Analysis:", 1)[-1].strip() if "Analysis:" in full_response else full_response
return jsonify({"response": ai_response})
return jsonify({"error": response.text}), response.status_code
except Exception as e:
return jsonify({"error": str(e)}), 500
if __name__ == "__main__":
app.run(debug=True)