Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
|
4 |
-
"""
|
5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
-
"""
|
7 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
def respond(
|
11 |
message,
|
@@ -17,32 +17,35 @@ def respond(
|
|
17 |
):
|
18 |
messages = [{"role": "system", "content": system_message}]
|
19 |
|
|
|
20 |
for val in history:
|
21 |
if val[0]:
|
22 |
messages.append({"role": "user", "content": val[0]})
|
23 |
if val[1]:
|
24 |
messages.append({"role": "assistant", "content": val[1]})
|
25 |
|
|
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
28 |
response = ""
|
29 |
|
30 |
-
|
31 |
-
|
|
|
|
|
32 |
max_tokens=max_tokens,
|
33 |
-
stream=True,
|
34 |
temperature=temperature,
|
35 |
top_p=top_p,
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
42 |
|
43 |
-
|
44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
45 |
-
"""
|
46 |
demo = gr.ChatInterface(
|
47 |
respond,
|
48 |
additional_inputs=[
|
@@ -59,6 +62,5 @@ demo = gr.ChatInterface(
|
|
59 |
],
|
60 |
)
|
61 |
|
62 |
-
|
63 |
if __name__ == "__main__":
|
64 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from openai import OpenAI
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
# API istemcisini başlatıyoruz
|
5 |
+
client = OpenAI(
|
6 |
+
base_url="https://integrate.api.nvidia.com/v1",
|
7 |
+
api_key="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" # Geçerli API anahtarını kullan
|
8 |
+
)
|
9 |
|
10 |
def respond(
|
11 |
message,
|
|
|
17 |
):
|
18 |
messages = [{"role": "system", "content": system_message}]
|
19 |
|
20 |
+
# Geçmiş mesajları ekliyoruz
|
21 |
for val in history:
|
22 |
if val[0]:
|
23 |
messages.append({"role": "user", "content": val[0]})
|
24 |
if val[1]:
|
25 |
messages.append({"role": "assistant", "content": val[1]})
|
26 |
|
27 |
+
# Kullanıcı mesajını ekliyoruz
|
28 |
messages.append({"role": "user", "content": message})
|
29 |
|
30 |
response = ""
|
31 |
|
32 |
+
# API'den gelen yanıtı işliyoruz
|
33 |
+
completion = client.chat.completions.create(
|
34 |
+
model="nvidia/nemotron-4-340b-instruct",
|
35 |
+
messages=messages,
|
36 |
max_tokens=max_tokens,
|
|
|
37 |
temperature=temperature,
|
38 |
top_p=top_p,
|
39 |
+
stream=True,
|
40 |
+
)
|
41 |
+
|
42 |
+
for chunk in completion:
|
43 |
+
if chunk.choices[0].delta.content is not None:
|
44 |
+
token = chunk.choices[0].delta.content
|
45 |
+
response += token
|
46 |
+
yield response
|
47 |
|
48 |
+
# Gradio arayüzünü tanımlıyoruz
|
|
|
|
|
49 |
demo = gr.ChatInterface(
|
50 |
respond,
|
51 |
additional_inputs=[
|
|
|
62 |
],
|
63 |
)
|
64 |
|
|
|
65 |
if __name__ == "__main__":
|
66 |
demo.launch()
|