studycode129 commited on
Commit
30b2090
·
verified ·
1 Parent(s): 8577d35

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ import requests
3
+ import os
4
+
5
+ app = Flask(__name__)
6
+
7
+ OPENROUTER_KEY = os.getenv("OPENROUTER_KEY", "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")
8
+
9
+ @app.route("/api/send", methods=["POST"])
10
+ def send():
11
+ data = request.get_json()
12
+ prompt = data.get("prompt")
13
+ model = data.get("model", "deepseek/deepseek-r1:free")
14
+
15
+ try:
16
+ response = requests.post(
17
+ "https://openrouter.ai/api/v1/chat/completions",
18
+ headers={
19
+ "Authorization": f"Bearer {OPENROUTER_KEY}",
20
+ "Content-Type": "application/json",
21
+ "HTTP-Referer": "https://huggingface.co/spaces/studycode129/Free_Web_LLM_Tester"
22
+ },
23
+ json={
24
+ "model": model,
25
+ "messages": [{"role": "user", "content": prompt}],
26
+ "temperature": 0.7
27
+ }
28
+ )
29
+ return jsonify(response.json())
30
+ except Exception as e:
31
+ return jsonify({"error": str(e)}), 500
32
+
33
+
34
+ if __name__ == "__main__":
35
+ app.run(host="0.0.0.0", port=7860)