Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from openai import OpenAI
|
| 3 |
+
|
| 4 |
+
client = OpenAI(
|
| 5 |
+
base_url="https://integrate.api.nvidia.com/v1",
|
| 6 |
+
api_key="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"
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
def generate_response(message, history):
|
| 10 |
+
history_openai_format = []
|
| 11 |
+
for human, assistant in history:
|
| 12 |
+
history_openai_format.append({"role": "user", "content": human})
|
| 13 |
+
history_openai_format.append({"role": "assistant", "content": assistant})
|
| 14 |
+
history_openai_format.append({"role": "user", "content": message})
|
| 15 |
+
|
| 16 |
+
completion = client.chat.completions.create(
|
| 17 |
+
model="nvidia/nemotron-4-340b-instruct",
|
| 18 |
+
messages=history_openai_format,
|
| 19 |
+
temperature=0.2,
|
| 20 |
+
top_p=0.7,
|
| 21 |
+
max_tokens=1024,
|
| 22 |
+
stream=True
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
response = ""
|
| 26 |
+
for chunk in completion:
|
| 27 |
+
if chunk.choices[0].delta.content is not None:
|
| 28 |
+
response += chunk.choices[0].delta.content
|
| 29 |
+
yield response
|
| 30 |
+
|
| 31 |
+
iface = gr.ChatInterface(
|
| 32 |
+
generate_response,
|
| 33 |
+
title="NVIDIA Nemotron-4 Sohbet Arayüzü",
|
| 34 |
+
description="Bir soru girin ve NVIDIA'nın Nemotron-4 modeli tarafından üretilen yanıtı alın. Sohbet geçmişi korunacaktır.",
|
| 35 |
+
examples=[
|
| 36 |
+
"GPU hesaplamanın harikalarıyla ilgili bir limerick yazabilir misin?",
|
| 37 |
+
"Yapay zeka ve etik arasındaki ilişkiyi açıklayabilir misin?",
|
| 38 |
+
"Kuantum bilgisayarların geleceği hakkında ne düşünüyorsun?"
|
| 39 |
+
],
|
| 40 |
+
cache_examples=False
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
iface.launch()
|