Spaces:
Running
Running
File size: 976 Bytes
e2b2f54 f8cc988 59b14a2 50babb3 e2b2f54 caaa69e 50babb3 bad7319 f8cc988 59b14a2 caaa69e dd29d8d 59b14a2 dd29d8d 59b14a2 dd29d8d 59b14a2 dd29d8d 59b14a2 4586819 e2b2f54 4586819 e2b2f54 59b14a2 e2b2f54 59b14a2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import os
import gradio as gr
from dotenv import load_dotenv
load_dotenv()
from langchain_nvidia_ai_endpoints import ChatNVIDIA
llm = ChatNVIDIA(
model="nvidia/nemotron-3-ultra-550b-a55b",
api_key=os.environ["NVIDIA_API_KEY"],
temperature=0.5
)
SYSTEM_PROMPT = """
You are a friendly and helpful AI assistant.
Rules:
- If the user says only greetings like "hi", "hello", "hey", respond in a warm and professional way.
- Your greeting should be: "Hi! I'm your AI assistant. How can I help you today?"
- Keep responses clear, polite, and beginner-friendly.
"""
def get_text_response(message, history):
conversation = SYSTEM_PROMPT + "\n\n"
for user_msg, bot_msg in history:
conversation += f"User: {user_msg}\nAssistant: {bot_msg}\n"
conversation += f"User: {message}\nAssistant:"
response = llm.invoke(conversation)
return response.content
demo = gr.ChatInterface(fn=get_text_response)
if __name__ == "__main__":
demo.launch() |