Spaces:
Running
Running
Update app.py
Browse files6 unmodified lines78910111255 unmodified lines686970717273747548 unmodified lines124125126127128129130131314 unmodified lines4464474484494504514526 unmodified linesfrom openai import OpenAIfrom config import API_KEY, MODEL, SYSTEM_PROMPT, ENDPOINT, EXAMPLES, DEFAULT_LOCALE, DEFAULT_THEMEfrom huggingface_hub import InferenceClientreact_imports = {"lucide-react": "https://esm.sh/lucide-react@0.525.0",55 unmodified linesmessages.append({'role': 'user', 'content': input_value})try:# Initialize HuggingFace InferenceClienthf_client = InferenceClient(model=MODEL, token=API_KEY)# Try using HuggingFace InferenceClient firstformatted_messages = [{"role": msg["role"], "content": msg["content"]} for msg in messages]48 unmodified linesexcept Exception as e:# Fallback to OpenAI client if HuggingFace client failstry:# Initialize OpenAI clientopenai_client = OpenAI(api_key=API_KEY, base_url=ENDPOINT + MODEL)generator = openai_client.chat.completions.create(model=MODEL,messages=messages,314 unmodified linesantd.Tour.Step(title="Step 3",description="Wait for the result.",get_target="() => document.querySelector('#output-container')")antd.Tour.Step(6 unmodified lines7891011121355 unmodified lines697071727374757677787980818248 unmodified lines131132133134135136137138139140141142143144314 unmodified lines4594604614624634644656 unmodified linesfrom openai import OpenAIfrom config import API_KEY, MODEL, SYSTEM_PROMPT, ENDPOINT, EXAMPLES, DEFAULT_LOCALE, DEFAULT_THEMEfrom huggingface_hub import InferenceClientimport osreact_imports = {"lucide-react": "https://esm.sh/lucide-react@0.525.0",55 unmodified linesmessages.append({'role': 'user', 'content': input_value})try:# Get API key from environment variable if not already setapi_key = API_KEY or os.getenv("HF_TOKEN") or os.getenv("OPENAI_API_KEY")if not api_key:raise ValueError("No API key found. Please set HF_TOKEN or OPENAI_API_KEY environment variable.")# Initialize HuggingFace InferenceClienthf_client = InferenceClient(model=MODEL, token=api_key)# Try using HuggingFace InferenceClient firstformatted_messages = [{"role": msg["role"], "content": msg["content"]} for msg in messages]48 unmodified linesexcept Exception as e:# Fallback to OpenAI client if HuggingFace client failstry:# Get API key from environment variable if not already setapi_key = API_KEY or os.getenv("HF_TOKEN") or os.getenv("OPENAI_API_KEY")if not api_key:raise ValueError("No API key found. Please set HF_TOKEN or OPENAI_API_KEY environment variable.")# Initialize OpenAI clientopenai_client = OpenAI(api_key=api_key, base_url=ENDPOINT + MODEL)generator = openai_client.chat.completions.create(model=MODEL,messages=messages,314 unmodified linesantd.Tour.Step(title="Step 3",description="Wait for the result.",get_target="() => document.querySelector('#output-container')")antd.Tour.Step(
app.py+16-3