Spaces:
Sleeping
Sleeping
Commit
·
bb971ee
1
Parent(s):
160e363
add open AI
Browse files
app.py
CHANGED
|
@@ -1,20 +1,28 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
-
import
|
| 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 |
-
|
| 10 |
-
"
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
demo = gr.Interface(
|
| 20 |
fn=generate_response,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
+
from openai import OpenAI
|
| 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 |
+
client = OpenAI(
|
| 10 |
+
base_url="https://api-inference.huggingface.co/v1/",
|
| 11 |
+
api_key=os.getenv('HUGGINGFACE_API_KEY')
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
messages = [
|
| 15 |
+
{"role": "user", "content": user_input}
|
| 16 |
+
]
|
| 17 |
+
|
| 18 |
+
response = client.chat.completions.create(
|
| 19 |
+
model="meta-llama/Llama-3.1-70B-Instruct",
|
| 20 |
+
messages=messages,
|
| 21 |
+
max_tokens=500,
|
| 22 |
+
stream=False
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
return response['choices'][0]['message']['content']
|
| 26 |
|
| 27 |
demo = gr.Interface(
|
| 28 |
fn=generate_response,
|