DevNumb commited on
Commit
7550451
·
verified ·
1 Parent(s): 0596a0e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -17
app.py CHANGED
@@ -1,24 +1,33 @@
 
1
  import requests
2
  import os
3
 
4
  API_KEY = os.getenv("OPENROUTER_API_KEY")
5
 
6
- response = requests.post(
7
- "https://openrouter.ai/api/v1/chat/completions",
8
- headers={
9
- "Authorization": f"Bearer {API_KEY}",
10
- "Content-Type": "application/json",
11
- },
12
- json={
13
- "model": "kwaipilot/kat-coder-pro:free",
14
- "messages": [
15
- {"role": "user", "content": "What is the meaning of life?"}
16
- ]
17
- }
18
- )
 
19
 
20
- # Parse JSON
21
- data = response.json()
 
 
 
 
 
 
 
 
22
 
23
- # Extract reply text
24
- print(data["choices"][0]["message"]["content"])
 
1
+ import gradio as gr
2
  import requests
3
  import os
4
 
5
  API_KEY = os.getenv("OPENROUTER_API_KEY")
6
 
7
+ def ask_llm(message):
8
+ response = requests.post(
9
+ "https://openrouter.ai/api/v1/chat/completions",
10
+ headers={
11
+ "Authorization": f"Bearer {API_KEY}",
12
+ "Content-Type": "application/json",
13
+ },
14
+ json={
15
+ "model": "kwaipilot/kat-coder-pro:free",
16
+ "messages": [{"role": "user", "content": message}]
17
+ }
18
+ )
19
+
20
+ data = response.json()
21
 
22
+ # return text output
23
+ return data["choices"][0]["message"]["content"]
24
+
25
+ # Gradio Interface
26
+ ui = gr.Interface(
27
+ fn=ask_llm,
28
+ inputs=gr.Textbox(label="Ask your question:"),
29
+ outputs=gr.Textbox(label="LLM Reply"),
30
+ title="OpenRouter Free Chat",
31
+ )
32
 
33
+ ui.launch()