Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ import uuid
|
|
| 9 |
app = Flask(__name__)
|
| 10 |
CORS(app)
|
| 11 |
|
| 12 |
-
openai.api_key
|
| 13 |
|
| 14 |
@app.route("/generate", methods=["POST"])
|
| 15 |
def generate():
|
|
@@ -32,14 +32,14 @@ def generate():
|
|
| 32 |
f"Do NOT add a conclusion unless asked. Only answer the questions."
|
| 33 |
)
|
| 34 |
|
| 35 |
-
|
| 36 |
-
model="gpt-3.5-turbo
|
| 37 |
messages=[{"role": "user", "content": prompt}],
|
| 38 |
max_tokens=3000,
|
| 39 |
temperature=0.7
|
| 40 |
)
|
| 41 |
|
| 42 |
-
result =
|
| 43 |
return jsonify({"response": result})
|
| 44 |
|
| 45 |
except Exception as e:
|
|
@@ -75,9 +75,5 @@ def export_word():
|
|
| 75 |
except Exception as e:
|
| 76 |
return jsonify({"error": str(e)}), 500
|
| 77 |
|
| 78 |
-
@app.route("/")
|
| 79 |
-
def home():
|
| 80 |
-
return "✅ UniSolve backend is running. Use /generate to POST data."
|
| 81 |
-
|
| 82 |
if __name__ == "__main__":
|
| 83 |
app.run(host="0.0.0.0", port=7860)
|
|
|
|
| 9 |
app = Flask(__name__)
|
| 10 |
CORS(app)
|
| 11 |
|
| 12 |
+
client = openai.OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
|
| 13 |
|
| 14 |
@app.route("/generate", methods=["POST"])
|
| 15 |
def generate():
|
|
|
|
| 32 |
f"Do NOT add a conclusion unless asked. Only answer the questions."
|
| 33 |
)
|
| 34 |
|
| 35 |
+
chat_response = client.chat.completions.create(
|
| 36 |
+
model="gpt-3.5-turbo",
|
| 37 |
messages=[{"role": "user", "content": prompt}],
|
| 38 |
max_tokens=3000,
|
| 39 |
temperature=0.7
|
| 40 |
)
|
| 41 |
|
| 42 |
+
result = chat_response.choices[0].message.content
|
| 43 |
return jsonify({"response": result})
|
| 44 |
|
| 45 |
except Exception as e:
|
|
|
|
| 75 |
except Exception as e:
|
| 76 |
return jsonify({"error": str(e)}), 500
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
if __name__ == "__main__":
|
| 79 |
app.run(host="0.0.0.0", port=7860)
|