File size: 1,052 Bytes
7e09388
 
36f2c68
7e09388
 
 
 
36f2c68
 
7e09388
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from flask import Flask, request, jsonify
from webscout.Provider.Deepinfra import DeepInfra
import os

# Initialize Flask app
app = Flask(__name__)

# Initialize System Prompt 
SYSTEM_PROMPT = os.getenv("SYSTEM_PROMPT")
# Instantiate the DeepInfra model
BASE_MODEL = DeepInfra(is_conversation=False, update_file=False, system_prompt=SYSTEM_PROMPT)

@app.route("/")
def index():
    return "🚀 Hugging Face Space API is running!"

@app.route("/chat", methods=["POST"])
def chat():
    try:
        data = request.get_json()
        prompt = data.get("prompt", "")

        if not prompt:
            return jsonify({"error": "Missing prompt"}), 400

        # Generate response using your DeepInfra wrapper
        response = BASE_MODEL.chat(prompt=prompt)

        return jsonify({
            "prompt": prompt,
            "response": response
        })

    except Exception as e:
        return jsonify({"error": str(e)}), 500

# Run locally (only useful for dev)
if __name__ == "__main__":
    app.run(debug=True, host="0.0.0.0", port=7860)