Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
add huggingface tab
Browse files- app.py +4 -1
- app_huggingface.py +67 -0
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
|
|
|
3 |
from app_allenai import demo as demo_allenai
|
4 |
from app_claude import demo as demo_claude
|
5 |
from app_experimental import demo as demo_experimental
|
@@ -20,6 +21,8 @@ from app_together import demo as demo_together
|
|
20 |
from app_xai import demo as demo_grok
|
21 |
|
22 |
with gr.Blocks(fill_height=True) as demo:
|
|
|
|
|
23 |
with gr.Tab("Grok"):
|
24 |
demo_grok.render()
|
25 |
with gr.Tab("Hyperbolic"):
|
@@ -41,7 +44,7 @@ with gr.Blocks(fill_height=True) as demo:
|
|
41 |
demo_claude.render()
|
42 |
with gr.Tab("Qwen"):
|
43 |
demo_qwen.render()
|
44 |
-
with gr.Tab("
|
45 |
demo_allenai.render()
|
46 |
with gr.Tab("Perplexity"):
|
47 |
demo_perplexity.render()
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
from app_huggingface import demo as demo_huggingface
|
4 |
from app_allenai import demo as demo_allenai
|
5 |
from app_claude import demo as demo_claude
|
6 |
from app_experimental import demo as demo_experimental
|
|
|
21 |
from app_xai import demo as demo_grok
|
22 |
|
23 |
with gr.Blocks(fill_height=True) as demo:
|
24 |
+
with gr.Tab("Hugging Face"):
|
25 |
+
demo_huggingface.render()
|
26 |
with gr.Tab("Grok"):
|
27 |
demo_grok.render()
|
28 |
with gr.Tab("Hyperbolic"):
|
|
|
44 |
demo_claude.render()
|
45 |
with gr.Tab("Qwen"):
|
46 |
demo_qwen.render()
|
47 |
+
with gr.Tab("Allen AI"):
|
48 |
demo_allenai.render()
|
49 |
with gr.Tab("Perplexity"):
|
50 |
demo_perplexity.render()
|
app_huggingface.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from gradio_client import Client
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
MODELS = {
|
5 |
+
"SmolVLM-Instruct": "akhaliq/smolvlm-chat"
|
6 |
+
}
|
7 |
+
|
8 |
+
def create_chat_fn(client):
|
9 |
+
def chat(message, history):
|
10 |
+
response = client.predict(
|
11 |
+
message=message,
|
12 |
+
image=None,
|
13 |
+
api_name="/chat"
|
14 |
+
)
|
15 |
+
return response
|
16 |
+
return chat
|
17 |
+
|
18 |
+
def set_client_for_session(model_name, request: gr.Request):
|
19 |
+
headers = {}
|
20 |
+
if request and hasattr(request, 'request') and hasattr(request.request, 'headers'):
|
21 |
+
x_ip_token = request.request.headers.get('x-ip-token')
|
22 |
+
if x_ip_token:
|
23 |
+
headers["X-IP-Token"] = x_ip_token
|
24 |
+
|
25 |
+
return Client(MODELS[model_name], headers=headers)
|
26 |
+
|
27 |
+
def safe_chat_fn(message, history, client):
|
28 |
+
if client is None:
|
29 |
+
return "Error: Client not initialized. Please refresh the page."
|
30 |
+
return create_chat_fn(client)(message, history)
|
31 |
+
|
32 |
+
with gr.Blocks() as demo:
|
33 |
+
|
34 |
+
client = gr.State()
|
35 |
+
|
36 |
+
model_dropdown = gr.Dropdown(
|
37 |
+
choices=list(MODELS.keys()),
|
38 |
+
value="SmolVLM-Instruct",
|
39 |
+
label="Select Model",
|
40 |
+
interactive=True
|
41 |
+
)
|
42 |
+
|
43 |
+
chat_interface = gr.ChatInterface(
|
44 |
+
fn=safe_chat_fn,
|
45 |
+
additional_inputs=[client]
|
46 |
+
)
|
47 |
+
|
48 |
+
# Update client when model changes
|
49 |
+
def update_model(model_name, request):
|
50 |
+
return set_client_for_session(model_name, request)
|
51 |
+
|
52 |
+
model_dropdown.change(
|
53 |
+
fn=update_model,
|
54 |
+
inputs=[model_dropdown],
|
55 |
+
outputs=[client],
|
56 |
+
)
|
57 |
+
|
58 |
+
# Initialize client on page load
|
59 |
+
demo.load(
|
60 |
+
fn=set_client_for_session,
|
61 |
+
inputs=gr.State("SmolVLM-Instruct"),
|
62 |
+
outputs=client,
|
63 |
+
)
|
64 |
+
|
65 |
+
demo = demo
|
66 |
+
|
67 |
+
|