Spaces:
Sleeping
Sleeping
Commit
·
160e363
1
Parent(s):
6d40d22
first commit
Browse files
app.py
CHANGED
@@ -1,7 +1,27 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import os
|
3 |
+
import requests
|
4 |
|
5 |
+
API_URL = "https://api-inference.huggingface.co/models/nvidia/Llama-3.1-Nemotron-70B-Instruct-HF"
|
6 |
+
headers = {"Authorization": f"Bearer {os.getenv('HUGGINGFACE_API_KEY')}"}
|
7 |
|
8 |
+
async def generate_response(user_input):
|
9 |
+
payload = {
|
10 |
+
"model": "nvidia/Llama-3.1-Nemotron-70B-Instruct-HF",
|
11 |
+
"messages": [{"role": "user", "content": user_input}],
|
12 |
+
"max_tokens": 16384,
|
13 |
+
"max_completion_tokens": 16384
|
14 |
+
}
|
15 |
+
|
16 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
17 |
+
return response.json()[0]['generated_text']
|
18 |
+
|
19 |
+
demo = gr.Interface(
|
20 |
+
fn=generate_response,
|
21 |
+
inputs=gr.Textbox(label="Your message"),
|
22 |
+
outputs=gr.Textbox(label="AI Response"),
|
23 |
+
title="AI Chat Interface",
|
24 |
+
description="Chat with Llama 3.1 Nemotron"
|
25 |
+
)
|
26 |
+
|
27 |
+
demo.launch()
|