Skip to content

Server.py #17

@fahimamiry-a11y

Description

@fahimamiry-a11y

from flask import Flask, request, jsonify
import requests

app = Flask(name)

OPENAI_API_KEY = "YOUR_API_KEY_HERE"

@app.route('/analyze', methods=['POST'])
def analyze():
data = request.json

feed = data.get("feed")
weight = data.get("weight")
mortality = data.get("mortality")

prompt = f"""
معلومات فارم:
Feed: {feed}
Weight: {weight}
Mortality: {mortality}

تحلیل بده:
- وضعیت فارم
- مشکل
- پیشنهاد
"""

response = requests.post(
    "https://api.openai.com/v1/chat/completions",
    headers={
        "Authorization": f"Bearer {OPENAI_API_KEY}",
        "Content-Type": "application/json"
    },
    json={
        "model": "gpt-4o-mini",
        "messages": [{"role": "user", "content": prompt}]
    }
)

result = response.json()
text = result["choices"][0]["message"]["content"]

return jsonify({"result": text})

app.run(host='0.0.0.0', port=5000)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions