Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,36 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
|
4 |
-
# Function to send your prompt to NVIDIA LLaMA 4 Maverick
|
5 |
def talk_to_llama(prompt):
|
6 |
-
url = "https://integrate.api.nvidia.com/v1/
|
7 |
headers = {
|
8 |
-
"Authorization": "Bearer
|
9 |
"Content-Type": "application/json"
|
10 |
}
|
11 |
data = {
|
12 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
}
|
|
|
14 |
response = requests.post(url, headers=headers, json=data)
|
15 |
-
|
16 |
try:
|
17 |
return response.json()["choices"][0]["message"]["content"]
|
18 |
-
except Exception
|
19 |
-
return f"
|
20 |
|
21 |
-
# Build the chatbot interface
|
22 |
chat = gr.Interface(
|
23 |
fn=talk_to_llama,
|
24 |
inputs="text",
|
25 |
outputs="text",
|
26 |
title="Chat with LLaMA 4 Maverick",
|
27 |
-
description="Ask anything! This chatbot uses NVIDIA’s LLaMA 4 Maverick 17B
|
28 |
)
|
29 |
|
30 |
chat.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
|
|
|
4 |
def talk_to_llama(prompt):
|
5 |
+
url = "https://integrate.api.nvidia.com/v1/chat/completions"
|
6 |
headers = {
|
7 |
+
"Authorization": "Bearer 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", # Replace if you regenerate key
|
8 |
"Content-Type": "application/json"
|
9 |
}
|
10 |
data = {
|
11 |
+
"model": "meta/llama-4-maverick-17b-128e-instruct",
|
12 |
+
"messages": [
|
13 |
+
{"role": "user", "content": prompt}
|
14 |
+
],
|
15 |
+
"max_tokens": 512,
|
16 |
+
"temperature": 1.0,
|
17 |
+
"top_p": 1.0,
|
18 |
+
"stream": False
|
19 |
}
|
20 |
+
|
21 |
response = requests.post(url, headers=headers, json=data)
|
22 |
+
|
23 |
try:
|
24 |
return response.json()["choices"][0]["message"]["content"]
|
25 |
+
except Exception:
|
26 |
+
return f"Error:\n{response.text}"
|
27 |
|
|
|
28 |
chat = gr.Interface(
|
29 |
fn=talk_to_llama,
|
30 |
inputs="text",
|
31 |
outputs="text",
|
32 |
title="Chat with LLaMA 4 Maverick",
|
33 |
+
description="Ask anything! This chatbot uses NVIDIA’s 3.5M token LLaMA 4 Maverick 17B model."
|
34 |
)
|
35 |
|
36 |
chat.launch()
|