artificialguybr's picture
Update app.py
1a85890 verified
raw
history blame
3.13 kB
import os
import gradio as gr
import requests
# Função modificada para incluir a obtenção da API key do ambiente
def query_model(context, question):
"""
Queries the Nemotron-3-8B-QA API with the provided question and context.
"""
invoke_url = "https://api.nvcf.nvidia.com/v2/nvcf/pexec/functions/0c60f14d-46cb-465e-b994-227e1c3d5047"
# Obtém a API key do ambiente
api_key = os.environ.get("NEMO_API_KEY")
if not api_key:
raise ValueError("Please set the NEMO_API_KEY environment variable.")
headers = {
"Authorization": f"Bearer {api_key}",
"accept": "text/event-stream",
"content-type": "application/json",
}
payload = {
"messages": [
{"content": context, "role": "context"},
{"content": question, "role": "user"},
],
"temperature": 0.2,
"top_p": 0.7,
"max_tokens": 1024,
"stream": True,
}
response = requests.post(invoke_url, headers=headers, json=payload, stream=True)
answer = ""
for line in response.iter_lines():
if line:
data = line.decode("utf-8")
if '"content":"' in data:
try:
content = data.split('"content":"')[1].split('"')[0]
answer += content
except IndexError:
continue
if data == "data:[DONE]":
break
return answer
iface = gr.Interface(
fn=query_model,
inputs=[
gr.Textbox(label="Context", lines=5),
gr.Textbox(label="Question"),
],
outputs="text",
title="Nemotron-3-8B-QA",
description="
<div style="text-align: center; font-size: 1.5em; margin-bottom: 20px;">
<strong>Unlock the Power of AI with Nemotron-3-8B-QA for Precision Question Answering</strong>
</div>
<p>
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.
</p>
<p>
<strong>How to Use:</strong>
</p>
<ol>
<li>Provide a <strong>context</strong> in the designated box, offering the model relevant information or background on your question.</li>
<li>Enter your <strong>question</strong> in the next box, making it as clear and specific as possible.</li>
<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>
</ol>
<p>
<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>
</p>
<p>
<strong>Created by:</strong> @artificialguybr (<a href="https://twitter.com/artificialguybr">Twitter</a>)
</p>
<p>
<strong>Discover more:</strong> <a href="https://artificialguy.com">artificialguy.com</a>
</p>
,
)
iface.launch()