leafspark commited on
Commit
8b9a116
1 Parent(s): 40e9cae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -1,8 +1,7 @@
1
  import gradio as gr
2
  import json
3
 
4
- def chat_completions(request: gr.Request):
5
- data = request.json
6
  response = {
7
  "id": "chatcmpl-123",
8
  "object": "chat.completion",
@@ -11,7 +10,7 @@ def chat_completions(request: gr.Request):
11
  "index": 0,
12
  "message": {
13
  "role": "assistant",
14
- "content": f"Placeholder response. Received: {data['messages'][-1]['content']}"
15
  },
16
  "finish_reason": "stop"
17
  }],
@@ -23,11 +22,13 @@ def chat_completions(request: gr.Request):
23
  }
24
  return json.dumps(response)
25
 
26
- with gr.Blocks() as demo:
27
- gr.Markdown("# Chat Completions API")
28
- gr.Markdown("Send a POST request to /v1/chat/completions")
 
 
 
 
29
 
30
- demo.queue()
31
- demo.launch()
32
-
33
- app = gr.mount_gradio_app(demo, "/v1/chat/completions", chat_completions)
 
1
  import gradio as gr
2
  import json
3
 
4
+ def chat_completions(message):
 
5
  response = {
6
  "id": "chatcmpl-123",
7
  "object": "chat.completion",
 
10
  "index": 0,
11
  "message": {
12
  "role": "assistant",
13
+ "content": "This is a placeholder response. The real model isn't loaded yet."
14
  },
15
  "finish_reason": "stop"
16
  }],
 
22
  }
23
  return json.dumps(response)
24
 
25
+ demo = gr.Interface(
26
+ fn=chat_completions,
27
+ inputs="json",
28
+ outputs="json",
29
+ title="Chat Completions API",
30
+ description="Send a POST request to /v1/chat/completions"
31
+ )
32
 
33
+ if __name__ == "__main__":
34
+ demo.launch()