Rocktiel commited on
Commit
9d85127
·
verified ·
1 Parent(s): 2057700

Update app.py

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