Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,15 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
import requests
|
|
|
4 |
|
5 |
-
# Função
|
6 |
-
def query_model(context, question):
|
7 |
"""
|
8 |
-
Queries the Nemotron-3-8B-QA API with the provided question and context.
|
|
|
9 |
"""
|
10 |
invoke_url = "https://api.nvcf.nvidia.com/v2/nvcf/pexec/functions/0c60f14d-46cb-465e-b994-227e1c3d5047"
|
11 |
-
# Obtém a API key do ambiente
|
12 |
api_key = os.environ.get("NEMO_API_KEY")
|
13 |
if not api_key:
|
14 |
raise ValueError("Please set the NEMO_API_KEY environment variable.")
|
@@ -17,16 +18,23 @@ def query_model(context, question):
|
|
17 |
"accept": "text/event-stream",
|
18 |
"content-type": "application/json",
|
19 |
}
|
|
|
|
|
|
|
|
|
|
|
20 |
payload = {
|
21 |
"messages": [
|
22 |
{"content": context, "role": "context"},
|
23 |
{"content": question, "role": "user"},
|
24 |
],
|
25 |
-
"temperature":
|
26 |
-
"top_p":
|
27 |
-
"max_tokens":
|
28 |
"stream": True,
|
|
|
29 |
}
|
|
|
30 |
response = requests.post(invoke_url, headers=headers, json=payload, stream=True)
|
31 |
answer = ""
|
32 |
for line in response.iter_lines():
|
@@ -42,45 +50,44 @@ def query_model(context, question):
|
|
42 |
break
|
43 |
return answer
|
44 |
|
|
|
45 |
iface = gr.Interface(
|
46 |
fn=query_model,
|
47 |
inputs=[
|
48 |
gr.Textbox(label="Context", lines=5),
|
49 |
gr.Textbox(label="Question"),
|
|
|
|
|
|
|
|
|
50 |
],
|
51 |
outputs="text",
|
52 |
title="Nemotron-3-8B-QA",
|
53 |
-
description="""
|
54 |
-
<div style="text-align: center; font-size: 1.5em; margin-bottom: 20px;">
|
55 |
<strong>Unlock the Power of AI with Nemotron-3-8B-QA for Precision Question Answering</strong>
|
56 |
</div>
|
57 |
-
|
58 |
<p>
|
59 |
Dive into the realm of advanced AI with the Nemotron-3-8B-QA, a state-of-the-art language model fine-tuned by NVIDIA for unparalleled question answering performance. Built upon the robust Nemotron-3-8B architecture, this 8 billion parameter model is designed to understand and follow instructions with remarkable accuracy, providing you with precise answers to your queries.
|
60 |
</p>
|
61 |
-
|
62 |
<p>
|
63 |
<strong>How to Use:</strong>
|
64 |
</p>
|
65 |
-
|
66 |
<ol>
|
67 |
<li>Provide a <strong>context</strong> in the designated box, offering the model relevant information or background on your question.</li>
|
68 |
<li>Enter your <strong>question</strong> in the next box, making it as clear and specific as possible.</li>
|
|
|
69 |
<li>Click <strong>Submit</strong> to receive a detailed and accurate answer based on the provided context and the model's extensive knowledge base.</li>
|
70 |
</ol>
|
71 |
-
|
72 |
<p>
|
73 |
<strong>This cutting-edge question answering service is powered by NVIDIA NGC, ensuring top-notch performance and reliability, and is completely free to use.</strong>
|
74 |
</p>
|
75 |
-
|
76 |
<p>
|
77 |
<strong>Created by:</strong> @artificialguybr (<a href="https://twitter.com/artificialguybr">Twitter</a>)
|
78 |
</p>
|
79 |
-
|
80 |
<p>
|
81 |
<strong>Discover more:</strong> <a href="https://artificialguy.com">artificialguy.com</a>
|
82 |
</p>
|
83 |
"""
|
84 |
)
|
85 |
|
86 |
-
iface.launch()
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
+
import random
|
5 |
|
6 |
+
# Função atualizada para incluir a geração de uma seed aleatória
|
7 |
+
def query_model(context, question, temperature, top_p, max_tokens, seed=""):
|
8 |
"""
|
9 |
+
Queries the Nemotron-3-8B-QA API with the provided question and context, allowing customization of temperature, top_p, max_tokens, and seed.
|
10 |
+
If no seed is provided, generates a random seed within the specified range.
|
11 |
"""
|
12 |
invoke_url = "https://api.nvcf.nvidia.com/v2/nvcf/pexec/functions/0c60f14d-46cb-465e-b994-227e1c3d5047"
|
|
|
13 |
api_key = os.environ.get("NEMO_API_KEY")
|
14 |
if not api_key:
|
15 |
raise ValueError("Please set the NEMO_API_KEY environment variable.")
|
|
|
18 |
"accept": "text/event-stream",
|
19 |
"content-type": "application/json",
|
20 |
}
|
21 |
+
|
22 |
+
# Gera uma seed aleatória se o usuário não especificou uma
|
23 |
+
if not seed:
|
24 |
+
seed = random.randint(0, 18446744073709552000)
|
25 |
+
|
26 |
payload = {
|
27 |
"messages": [
|
28 |
{"content": context, "role": "context"},
|
29 |
{"content": question, "role": "user"},
|
30 |
],
|
31 |
+
"temperature": float(temperature),
|
32 |
+
"top_p": float(top_p),
|
33 |
+
"max_tokens": int(max_tokens),
|
34 |
"stream": True,
|
35 |
+
"seed": int(seed), # Usa a seed especificada ou a gerada aleatoriamente
|
36 |
}
|
37 |
+
|
38 |
response = requests.post(invoke_url, headers=headers, json=payload, stream=True)
|
39 |
answer = ""
|
40 |
for line in response.iter_lines():
|
|
|
50 |
break
|
51 |
return answer
|
52 |
|
53 |
+
# Interface do Gradio atualizada para incluir a entrada da seed com limitação de valor
|
54 |
iface = gr.Interface(
|
55 |
fn=query_model,
|
56 |
inputs=[
|
57 |
gr.Textbox(label="Context", lines=5),
|
58 |
gr.Textbox(label="Question"),
|
59 |
+
gr.Slider(label="Temperature", minimum=0.1, maximum=1.0, step=0.1, default=0.2),
|
60 |
+
gr.Slider(label="Top P", minimum=0.1, maximum=1.0, step=0.1, default=0.7),
|
61 |
+
gr.Slider(label="Max Tokens", minimum=1, maximum=1024, step=63, default=1024),
|
62 |
+
gr.Textbox(label="Seed (optional, 0 to 18446744073709552000)", optional=True),
|
63 |
],
|
64 |
outputs="text",
|
65 |
title="Nemotron-3-8B-QA",
|
66 |
+
description="""<div style="text-align: center; font-size: 1.5em; margin-bottom: 20px;">
|
|
|
67 |
<strong>Unlock the Power of AI with Nemotron-3-8B-QA for Precision Question Answering</strong>
|
68 |
</div>
|
|
|
69 |
<p>
|
70 |
Dive into the realm of advanced AI with the Nemotron-3-8B-QA, a state-of-the-art language model fine-tuned by NVIDIA for unparalleled question answering performance. Built upon the robust Nemotron-3-8B architecture, this 8 billion parameter model is designed to understand and follow instructions with remarkable accuracy, providing you with precise answers to your queries.
|
71 |
</p>
|
|
|
72 |
<p>
|
73 |
<strong>How to Use:</strong>
|
74 |
</p>
|
|
|
75 |
<ol>
|
76 |
<li>Provide a <strong>context</strong> in the designated box, offering the model relevant information or background on your question.</li>
|
77 |
<li>Enter your <strong>question</strong> in the next box, making it as clear and specific as possible.</li>
|
78 |
+
<li>Adjust <strong>Temperature</strong>, <strong>Top P</strong>, <strong>Max Tokens</strong>, and <strong>Seed</strong> (optional) as needed to customize the response.</li>
|
79 |
<li>Click <strong>Submit</strong> to receive a detailed and accurate answer based on the provided context and the model's extensive knowledge base.</li>
|
80 |
</ol>
|
|
|
81 |
<p>
|
82 |
<strong>This cutting-edge question answering service is powered by NVIDIA NGC, ensuring top-notch performance and reliability, and is completely free to use.</strong>
|
83 |
</p>
|
|
|
84 |
<p>
|
85 |
<strong>Created by:</strong> @artificialguybr (<a href="https://twitter.com/artificialguybr">Twitter</a>)
|
86 |
</p>
|
|
|
87 |
<p>
|
88 |
<strong>Discover more:</strong> <a href="https://artificialguy.com">artificialguy.com</a>
|
89 |
</p>
|
90 |
"""
|
91 |
)
|
92 |
|
93 |
+
iface.launch()
|