add playai
Browse filesFiles changed (4)
- app.py+3
- app_huggingface.py+15-13
- app_playai.pyAdded+7
- requirements.txt+1
12345614 unmodified lines2122232425262728import gradio as gr
from app_playai import demo as demo_playaifrom app_allenai import demo as demo_allenaifrom app_claude import demo as demo_claudefrom app_experimental import demo as demo_experimental14 unmodified linesfrom app_xai import demo as demo_grok
with gr.Blocks(fill_height=True) as demo: with gr.Tab("PlayAI"): demo_playai.render() with gr.Tab("Grok"): demo_grok.render() with gr.Tab("Hyperbolic"):123456789109111211131415167 unmodified lines242526252627282930312 unmodified lines34353637353839404142434413 unmodified lines5859605556576159626361646566676869676870717273747573from gradio_client import Clientimport gradio as grimport os
MODELS = { "SmolVLM-Instruct": "akhaliq/SmolVLM-Instruct"}
def create_chat_fn(client): def chat(message, history): def chat(message, history, files=[]): response = client.predict( message={"text": message, "files": []}, message={"text": message, "files": files}, system_prompt="You are a helpful AI assistant.", temperature=0.7, max_new_tokens=1024,7 unmodified lines
def set_client_for_session(model_name, request: gr.Request): headers = {} if request and hasattr(request, 'request') and hasattr(request.request, 'headers'): x_ip_token = request.request.headers.get('x-ip-token') 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_token 2 unmodified linesdef 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) return create_chat_fn(client)(message, history) except Exception as e: print(f"Error during chat: {str(e)}") return f"Error during chat: {str(e)}"
with gr.Blocks() as demo: 13 unmodified lines ) # Update client when model changes def update_model(model_name, request): return set_client_for_session(model_name, request) model_dropdown.change( fn=update_model, fn=set_client_for_session, inputs=[model_dropdown], outputs=[client], outputs=[client] ) # Initialize client on page load demo.load( fn=set_client_for_session, inputs=gr.State("SmolVLM-Instruct"), outputs=client, inputs=[gr.State("SmolVLM-Instruct")], outputs=[client] )
demo = demo
demo.launch()1234567import gradio as grimport playai_gradio
demo =gr.load( name='PlayDialog', src=playai_gradio.registry,)395 unmodified lines396397398399395 unmodified lines # via gradio-clientxai-gradio==0.0.2 # via anychat (pyproject.toml)playai-gradio @ git+https://github.com/AK391/playai-gradio.gitapp.py+3
app_huggingface.py+15-13
app_playai.pyAdded+7
requirements.txt+1