Spaces:
No application file
No application file
Download App.py from MafuNexusGroup/README: direct link, hf CLI and curl.
- Browser
- Download file 995 Bytes
-
https://huggingface.co/spaces/MafuNexusGroup/README/resolve/main/App.py
- Command line
-
hf download hf://spaces/MafuNexusGroup/README/App.py
-
curl -L -o App.py https://huggingface.co/spaces/MafuNexusGroup/README/resolve/main/App.py
995 Bytes
| import os | |
| import requests | |
| from flask import Flask, request, jsonify | |
| app = Flask(__name__) | |
| HF_TOKEN = os.getenv("HF_TOKEN") | |
| API_URL = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta" | |
| headers = { | |
| "Authorization": f"Bearer {HF_TOKEN}" | |
| } | |
| def query(prompt): | |
| response = requests.post(API_URL, headers=headers, json={ | |
| "inputs": prompt | |
| }) | |
| return response.json() | |
| def chat(): | |
| data = request.json | |
| user_message = data.get("message") | |
| system_prompt = """ | |
| You are an AI assistant for a logistics, agriculture, and job marketplace platform. | |
| Help users find jobs, match workers, suggest pricing, and give smart business advice. | |
| """ | |
| full_prompt = system_prompt + "\nUser: " + user_message | |
| ai_response = query(full_prompt) | |
| return jsonify(ai_response) | |
| def home(): | |
| return "AI Backend is running" | |
| if __name__ == "__main__": | |
| app.run(host="0.0.0.0", port=7860) |