Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,29 @@
|
|
| 1 |
-
from flask import Flask, request, jsonify, render_template
|
| 2 |
-
from g4f.client import ClientFactory
|
| 3 |
-
|
| 4 |
-
app = Flask(__name__)
|
| 5 |
-
client = ClientFactory.create_client("gemini")
|
| 6 |
-
|
| 7 |
-
@app.route('/')
|
| 8 |
-
def index():
|
| 9 |
-
return render_template('index.html')
|
| 10 |
-
|
| 11 |
-
@app.route('/run', methods=['POST'])
|
| 12 |
-
def run_code():
|
| 13 |
-
data = request.json
|
| 14 |
-
prompt = data.get('code', '')
|
| 15 |
-
try:
|
| 16 |
-
response = client.chat.completions.create(
|
| 17 |
-
model="models/gemini-flash-latest",
|
| 18 |
-
messages=[{"role": "user", "content": prompt}],
|
| 19 |
-
)
|
| 20 |
-
print(response.choices[0].message.content)
|
| 21 |
-
return jsonify({"output": response.choices[0].message.content})
|
| 22 |
-
except Exception as e:
|
| 23 |
-
# Имитируем ошибку
|
| 24 |
-
print(e)
|
| 25 |
-
return jsonify({"output": f"Traceback (most recent call last):\n File \"main.py\", line 1, in <module>\nRunTimeError: AI server connection failed: {str(e)}"}), 500
|
| 26 |
-
|
| 27 |
-
if __name__ == '__main__':
|
| 28 |
-
# Слушаем на всех интерфейсах, порт 5000.
|
| 29 |
app.run(host='0.0.0.0', port=5000)
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify, render_template
|
| 2 |
+
from g4f.client import ClientFactory
|
| 3 |
+
|
| 4 |
+
app = Flask(__name__)
|
| 5 |
+
client = ClientFactory.create_client("gemini")
|
| 6 |
+
|
| 7 |
+
@app.route('/')
|
| 8 |
+
def index():
|
| 9 |
+
return render_template('../index.html')
|
| 10 |
+
|
| 11 |
+
@app.route('/run', methods=['POST'])
|
| 12 |
+
def run_code():
|
| 13 |
+
data = request.json
|
| 14 |
+
prompt = data.get('code', '')
|
| 15 |
+
try:
|
| 16 |
+
response = client.chat.completions.create(
|
| 17 |
+
model="models/gemini-flash-latest",
|
| 18 |
+
messages=[{"role": "user", "content": prompt}],
|
| 19 |
+
)
|
| 20 |
+
print(response.choices[0].message.content)
|
| 21 |
+
return jsonify({"output": response.choices[0].message.content})
|
| 22 |
+
except Exception as e:
|
| 23 |
+
# Имитируем ошибку
|
| 24 |
+
print(e)
|
| 25 |
+
return jsonify({"output": f"Traceback (most recent call last):\n File \"main.py\", line 1, in <module>\nRunTimeError: AI server connection failed: {str(e)}"}), 500
|
| 26 |
+
|
| 27 |
+
if __name__ == '__main__':
|
| 28 |
+
# Слушаем на всех интерфейсах, порт 5000.
|
| 29 |
app.run(host='0.0.0.0', port=5000)
|