Update app.py
Browse filesGPT-4 "mixer" added to HF Client completion for testing of mixed model output.
app.py
CHANGED
@@ -1,11 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
"""
|
7 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
|
|
|
|
9 |
|
10 |
def respond(
|
11 |
message,
|
@@ -14,6 +15,7 @@ def respond(
|
|
14 |
max_tokens,
|
15 |
temperature,
|
16 |
top_p,
|
|
|
17 |
):
|
18 |
messages = [{"role": "system", "content": system_message}]
|
19 |
|
@@ -27,21 +29,31 @@ def respond(
|
|
27 |
|
28 |
response = ""
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
demo = gr.ChatInterface(
|
46 |
respond,
|
47 |
additional_inputs=[
|
@@ -55,9 +67,15 @@ demo = gr.ChatInterface(
|
|
55 |
step=0.05,
|
56 |
label="Top-p (nucleus sampling)",
|
57 |
),
|
|
|
|
|
|
|
|
|
|
|
58 |
],
|
|
|
|
|
59 |
)
|
60 |
|
61 |
-
|
62 |
if __name__ == "__main__":
|
63 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
+
import openai
|
4 |
|
5 |
+
# Initialize Hugging Face client
|
6 |
+
hf_client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
|
|
|
|
7 |
|
8 |
+
# OpenAI GPT-4 API key
|
9 |
+
openai.api_key = "sk-proj-vA5kIjVnIcoxmcsgTEfBT3BlbkFJ2aD0n6zIUcYzpcu48QHK"
|
10 |
|
11 |
def respond(
|
12 |
message,
|
|
|
15 |
max_tokens,
|
16 |
temperature,
|
17 |
top_p,
|
18 |
+
model_choice,
|
19 |
):
|
20 |
messages = [{"role": "system", "content": system_message}]
|
21 |
|
|
|
29 |
|
30 |
response = ""
|
31 |
|
32 |
+
if model_choice == "Hugging Face Model":
|
33 |
+
for message in hf_client.chat_completion(
|
34 |
+
messages,
|
35 |
+
max_tokens=max_tokens,
|
36 |
+
stream=True,
|
37 |
+
temperature=temperature,
|
38 |
+
top_p=top_p,
|
39 |
+
):
|
40 |
+
token = message.choices[0].delta.content
|
41 |
+
response += token
|
42 |
+
yield response
|
43 |
+
elif model_choice == "OpenAI GPT-4":
|
44 |
+
response_openai = openai.ChatCompletion.create(
|
45 |
+
model="gpt-4",
|
46 |
+
messages=messages,
|
47 |
+
max_tokens=max_tokens,
|
48 |
+
temperature=temperature,
|
49 |
+
top_p=top_p,
|
50 |
+
stream=True
|
51 |
+
)
|
52 |
+
for message in response_openai:
|
53 |
+
response += message['choices'][0]['delta'].get('content', '')
|
54 |
+
yield response
|
55 |
+
|
56 |
+
# Create the Gradio interface
|
57 |
demo = gr.ChatInterface(
|
58 |
respond,
|
59 |
additional_inputs=[
|
|
|
67 |
step=0.05,
|
68 |
label="Top-p (nucleus sampling)",
|
69 |
),
|
70 |
+
gr.Radio(
|
71 |
+
choices=["Hugging Face Model", "OpenAI GPT-4"],
|
72 |
+
value="Hugging Face Model",
|
73 |
+
label="Choose Model"
|
74 |
+
)
|
75 |
],
|
76 |
+
title="GPT-4 vs Hugging Face Model Comparison",
|
77 |
+
description="Compare responses between a Hugging Face model and OpenAI's GPT-4."
|
78 |
)
|
79 |
|
|
|
80 |
if __name__ == "__main__":
|
81 |
+
demo.launch()
|