Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,16 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
-
from huggingface_hub import login
|
4 |
-
from huggingface_hub import InferenceClient
|
5 |
-
import spaces
|
6 |
|
7 |
# Authenticate with Hugging Face API
|
8 |
-
api_key = os.getenv("
|
9 |
login(api_key)
|
10 |
|
11 |
# Initialize clients for different models
|
12 |
llama_client = InferenceClient("meta-llama/Llama-3.1-70B-Instruct")
|
13 |
-
gpt_client = InferenceClient("openai/gpt-4")
|
14 |
|
15 |
# Define the response function
|
16 |
-
@spaces.GPU
|
17 |
def respond(
|
18 |
message,
|
19 |
history: list[dict],
|
@@ -23,11 +20,9 @@ def respond(
|
|
23 |
top_p,
|
24 |
selected_models,
|
25 |
):
|
26 |
-
# Prepare input messages
|
27 |
messages = [{"role": "system", "content": system_message}] + history
|
28 |
messages.append({"role": "user", "content": message})
|
29 |
|
30 |
-
# Collect responses from selected models
|
31 |
responses = {}
|
32 |
|
33 |
if "Llama" in selected_models:
|
@@ -50,7 +45,7 @@ def respond(
|
|
50 |
|
51 |
return responses
|
52 |
|
53 |
-
# Build
|
54 |
def create_demo():
|
55 |
return gr.Blocks().add(
|
56 |
gr.Markdown("# AI Model Comparison Tool 🌟"),
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
+
from huggingface_hub import login, InferenceClient
|
|
|
|
|
4 |
|
5 |
# Authenticate with Hugging Face API
|
6 |
+
api_key = os.getenv("TOKEN")
|
7 |
login(api_key)
|
8 |
|
9 |
# Initialize clients for different models
|
10 |
llama_client = InferenceClient("meta-llama/Llama-3.1-70B-Instruct")
|
11 |
+
gpt_client = InferenceClient("openai/gpt-4")
|
12 |
|
13 |
# Define the response function
|
|
|
14 |
def respond(
|
15 |
message,
|
16 |
history: list[dict],
|
|
|
20 |
top_p,
|
21 |
selected_models,
|
22 |
):
|
|
|
23 |
messages = [{"role": "system", "content": system_message}] + history
|
24 |
messages.append({"role": "user", "content": message})
|
25 |
|
|
|
26 |
responses = {}
|
27 |
|
28 |
if "Llama" in selected_models:
|
|
|
45 |
|
46 |
return responses
|
47 |
|
48 |
+
# Build Gradio app
|
49 |
def create_demo():
|
50 |
return gr.Blocks().add(
|
51 |
gr.Markdown("# AI Model Comparison Tool 🌟"),
|