add huggingface inference providers
Browse filesFiles changed (3)
- app_huggingface.py+15-62
- pyproject.toml+1-1
- requirements.txt+3-2
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667import gradio as grfrom gradio_client import Client, handle_fileMODELS = {"SmolVLM-Instruct": "akhaliq/SmolVLM-Instruct"}def create_chat_fn(client):def chat(message, history):# Extract text and files from the messagetext = message.get("text", "")files = message.get("files", [])# Handle file uploads if presentprocessed_files = [handle_file(f) for f in files]response = client.predict(message={"text": text, "files": processed_files},system_prompt="You are a helpful AI assistant.",temperature=0.7,max_new_tokens=1024,top_k=40,repetition_penalty=1.1,top_p=0.95,api_name="/chat",)return responsereturn chatdef set_client_for_session(model_name, request: gr.Request):headers = {}if request and hasattr(request, "headers"):x_ip_token = request.headers.get("x-ip-token")if x_ip_token:headers["X-IP-Token"] = x_ip_tokenreturn Client(MODELS[model_name], headers=headers)def safe_chat_fn(message, history, client):if client is None:return "Error: Client not initialized. Please refresh the page."try:return create_chat_fn(client)(message, history)except Exception as e:print(f"Error during chat: {e!s}")return f"Error during chat: {e!s}"with gr.Blocks() as demo:client = gr.State()model_dropdown = gr.Dropdown(choices=list(MODELS.keys()), value="SmolVLM-Instruct", label="Select Model", interactive=True)chat_interface = gr.ChatInterface(fn=safe_chat_fn, additional_inputs=[client], multimodal=True)# Update client when model changesmodel_dropdown.change(fn=set_client_for_session, inputs=[model_dropdown], outputs=[client])# Initialize client on page loaddemo.load(fn=set_client_for_session, inputs=[gr.State("SmolVLM-Instruct")], outputs=[client])if __name__ == "__main__":demo.launch()1234567891011121314151617181920import ai_gradiofrom utils_ai_gradio import get_app# Get the hyperbolic models but keep their full names for loadingHUGGINGFACE_MODELS_FULL = [k for k in ai_gradio.registry.keys() if k.startswith("huggingface:")]# Create display names without the prefixHUGGINGFACE_MODELS_DISPLAY = [k.replace("huggingface:", "") for k in HUGGINGFACE_MODELS_FULL]# Create and launch the interface using get_app utilitydemo = get_app(models=HUGGINGFACE_MODELS_FULL, # Use the full names with prefixdefault_model=HUGGINGFACE_MODELS_FULL[0],dropdown_label="Select Huggingface Model",choices=HUGGINGFACE_MODELS_DISPLAY, # Display names without prefixfill_height=True,coder=True,)
37 unmodified lines3839404142434437 unmodified lines"langchain>=0.3.14","chromadb>=0.5.23","openai>=1.55.0","ai-gradio[crewai,deepseek,gemini,groq,hyperbolic,openai,smolagents,transformers, langchain, mistral,minimax,nvidia, qwen, openrouter]>=0.2.46",][tool.uv.sources]37 unmodified lines3839404142434437 unmodified lines"langchain>=0.3.14","chromadb>=0.5.23","openai>=1.55.0","ai-gradio[crewai,deepseek,gemini,groq,hyperbolic,openai,smolagents,transformers, langchain, mistral,minimax,nvidia, qwen, openrouter, huggingface]>=0.2.47",][tool.uv.sources]
1 unmodified line2345678419 unmodified lines4284294304314324334344354361 unmodified line# uv pip compile pyproject.toml -o requirements.txtaccelerate==1.2.1# via ai-gradioai-gradio==0.2.46# via anychat (pyproject.toml)aiofiles==23.2.1# via gradio419 unmodified lines# langchain-communityhttpx-ws==0.7.1# via fireworks-aihuggingface-hub==0.27.1# via# accelerate# gradio# gradio-client# tokenizers1 unmodified line2345678419 unmodified lines4284294304314324334344354364371 unmodified line# uv pip compile pyproject.toml -o requirements.txtaccelerate==1.2.1# via ai-gradioai-gradio==0.2.47# via anychat (pyproject.toml)aiofiles==23.2.1# via gradio419 unmodified lines# langchain-communityhttpx-ws==0.7.1# via fireworks-aihuggingface-hub==0.28.1# via# accelerate# ai-gradio# gradio# gradio-client# tokenizers
app_huggingface.py+15-62
pyproject.toml+1-1
requirements.txt+3-2