from flask import Flask, jsonify, request
from flask_restful import reqparse
from dotenv import load_dotenv
from PIL import Image
import google.generativeai as genai
import io
genai.configure(api_key="Example")
app = Flask(__name__)
def get_gemini_response(category, title, description, image):
model = genai.GenerativeModel('gemini-1.5-flash')
# Combining category, title, and description into a prompt
input_text = f"Category: {category}\nTitle:
{title}\nDescription: {description}"
if input_text:
response = model.generate_content([fUser: {input_text}', image])
else:
response = model.generate_content(image)
return response.text
enter code here
@app.route('/check-category-post', methods=['POST'])
def evaluate_image():
try:
# Extract form data and file
category = request.form.get('category')
title = request.form.get('title')
description = request.form.get('description')
file = request.files.get('image')
print("Category:", category)
print("Title:", title)
print("Description:", description)
print("File:", file)
if not category or not title or not description or not file:
return jsonify({"error": "Category, title, description,
and image file are required"}), 400
# Open the image
image = Image.open(io.BytesIO(file.read()))
# Pass the category, title, description, and image to the
Gemini model
response_text = get_gemini_response(category, title,
description, image)
return jsonify({"response": response_text}), 200
except Exception as e:
print("Error:", str(e)) # Log the error for debugging
return jsonify({"error": str(e)}), 500
@app.route('/check-category-post', methods=['POST'])
def check_category_post():
# Log headers and raw data for debugging
print("Headers:", request.headers)
print("Raw Data:", request.data)
# Set up reqparse
parser = reqparse.RequestParser()
parser.add_argument('cpf', type=str, required=True,
location='args') # Expecting args
args = parser.parse_args()
return jsonify({"message": "Success", "data": args}), 200
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)
Я пытаюсь подключиться к API, но появляется эта ошибка. 158.38.176.102 — это IP-адрес моего сервера, на котором размещается мой проект Python.Это код. [code]from flask import Flask, jsonify, request from flask_restful import reqparse from dotenv import load_dotenv from PIL import Image import google.generativeai as genai import io
genai.configure(api_key="Example")
app = Flask(__name__)
def get_gemini_response(category, title, description, image): model = genai.GenerativeModel('gemini-1.5-flash') # Combining category, title, and description into a prompt input_text = f"Category: {category}\nTitle: {title}\nDescription: {description}"
if input_text: response = model.generate_content([fUser: {input_text}', image]) else: response = model.generate_content(image) return response.text enter code here @app.route('/check-category-post', methods=['POST']) def evaluate_image(): try: # Extract form data and file category = request.form.get('category') title = request.form.get('title') description = request.form.get('description') file = request.files.get('image')
if not category or not title or not description or not file: return jsonify({"error": "Category, title, description, and image file are required"}), 400
# Open the image image = Image.open(io.BytesIO(file.read()))
# Pass the category, title, description, and image to the Gemini model response_text = get_gemini_response(category, title, description, image)
return jsonify({"response": response_text}), 200
except Exception as e: print("Error:", str(e)) # Log the error for debugging return jsonify({"error": str(e)}), 500
ошибка : 403 Запросы от реферера заблокированы.
Я пытаюсь подключиться к API, но появляется эта ошибка кроме того, 158.38.176.102 — это IP-адрес моего сервера, на котором размещается мой проект Python.
API консоли Google
хочет решить эту проблему....
Описание проблемы:
Я использую API данных Youtube для получения некоторых видео с помощью ключа API в приложении Flutter.
Я использовал этот код для получения своих данных:
const FETCH_LINK =...
Я пытаюсь интегрировать поддержку реферера установки через Библиотеку рефереров установки Play . Приложение отлично работает в качестве отладочной сборки, но при тестировании потока в выпускной сборке приложение вылетает с вышеупомянутой ошибкой....