Ilke Ileri commited on
Commit
e48c956
·
1 Parent(s): e683a4c

Fix CORS issues and add request logging for Vapi integration

Browse files
Files changed (2) hide show
  1. README.md +17 -1
  2. app.py +20 -2
README.md CHANGED
@@ -5,6 +5,22 @@ colorFrom: pink
5
  colorTo: purple
6
  sdk: docker
7
  pinned: false
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  colorTo: purple
6
  sdk: docker
7
  pinned: false
8
+ app_port: 7860
9
  ---
10
 
11
+ # Vapi Gemma API
12
+
13
+ Custom fine-tuned Gemma model for sales conversations via Vapi integration.
14
+
15
+ ## API Endpoints
16
+
17
+ - `GET /` - Health check
18
+ - `POST /chat/completions` - Chat completions (OpenAI-compatible format)
19
+
20
+ ## Usage
21
+
22
+ ```bash
23
+ curl -X POST https://ilkeileri-vapi-gemma-api.hf.space/chat/completions \
24
+ -H "Content-Type: application/json" \
25
+ -d '{"messages": [{"role": "user", "content": "Your question here"}]}'
26
+ ```
app.py CHANGED
@@ -6,7 +6,16 @@ import torch
6
  import os
7
 
8
  app = Flask(__name__)
9
- CORS(app)
 
 
 
 
 
 
 
 
 
10
 
11
  # Hugging Face token'ı environment variable'dan al
12
  HF_TOKEN = os.environ.get("HF_TOKEN")
@@ -43,8 +52,17 @@ def health_check():
43
 
44
  @app.route("/chat/completions", methods=["POST", "OPTIONS"])
45
  def chat_completions():
 
 
 
 
 
46
  if request.method == "OPTIONS":
47
- return "", 200
 
 
 
 
48
 
49
  try:
50
  data = request.get_json()
 
6
  import os
7
 
8
  app = Flask(__name__)
9
+ # Tüm origin'lere izin ver - Vapi için gerekli
10
+ CORS(app, resources={
11
+ r"/*": {
12
+ "origins": "*",
13
+ "methods": ["GET", "POST", "OPTIONS"],
14
+ "allow_headers": ["Content-Type", "Authorization"],
15
+ "expose_headers": ["Content-Type"],
16
+ "supports_credentials": False
17
+ }
18
+ })
19
 
20
  # Hugging Face token'ı environment variable'dan al
21
  HF_TOKEN = os.environ.get("HF_TOKEN")
 
52
 
53
  @app.route("/chat/completions", methods=["POST", "OPTIONS"])
54
  def chat_completions():
55
+ # Log incoming request
56
+ print(f"Received {request.method} request from {request.remote_addr}")
57
+ print(f"Headers: {dict(request.headers)}")
58
+
59
+ # OPTIONS isteği için preflight response
60
  if request.method == "OPTIONS":
61
+ response = jsonify({"status": "ok"})
62
+ response.headers.add("Access-Control-Allow-Origin", "*")
63
+ response.headers.add("Access-Control-Allow-Headers", "Content-Type,Authorization")
64
+ response.headers.add("Access-Control-Allow-Methods", "GET,POST,OPTIONS")
65
+ return response, 200
66
 
67
  try:
68
  data = request.get_json()