Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,10 +2,12 @@ import gradio as gr
|
|
2 |
from openai import OpenAI
|
3 |
import os
|
4 |
|
|
|
5 |
ACCESS_TOKEN = os.getenv("HF_TOKEN")
|
6 |
|
7 |
print("Access token loaded.")
|
8 |
|
|
|
9 |
client = OpenAI(
|
10 |
base_url="https://api-inference.huggingface.co/v1/",
|
11 |
api_key=ACCESS_TOKEN,
|
@@ -27,8 +29,10 @@ def respond(
|
|
27 |
print(f"Received message: {message}")
|
28 |
print(f"History: {history}")
|
29 |
print(f"System message: {system_message}")
|
30 |
-
print(f"Max tokens: {max_tokens}, Temperature: {temperature}, Top-P: {top_p}
|
|
|
31 |
|
|
|
32 |
messages = [{"role": "system", "content": system_message}]
|
33 |
|
34 |
for val in history:
|
@@ -62,10 +66,12 @@ def respond(
|
|
62 |
|
63 |
print("Completed response generation.")
|
64 |
|
|
|
65 |
chatbot = gr.Chatbot(height=600)
|
66 |
|
67 |
print("Chatbot interface created.")
|
68 |
|
|
|
69 |
demo = gr.ChatInterface(
|
70 |
respond,
|
71 |
additional_inputs=[
|
@@ -80,7 +86,7 @@ demo = gr.ChatInterface(
|
|
80 |
label="Top-P",
|
81 |
),
|
82 |
gr.Slider(
|
83 |
-
minimum
|
84 |
maximum=2.0,
|
85 |
value=0.0,
|
86 |
step=0.1,
|
@@ -95,10 +101,10 @@ demo = gr.ChatInterface(
|
|
95 |
),
|
96 |
gr.Slider(
|
97 |
minimum=-1,
|
98 |
-
maximum=
|
99 |
value=-1,
|
100 |
step=1,
|
101 |
-
label="Seed
|
102 |
),
|
103 |
],
|
104 |
fill_height=True,
|
|
|
2 |
from openai import OpenAI
|
3 |
import os
|
4 |
|
5 |
+
# Load the Hugging Face access token from environment variables
|
6 |
ACCESS_TOKEN = os.getenv("HF_TOKEN")
|
7 |
|
8 |
print("Access token loaded.")
|
9 |
|
10 |
+
# Initialize the OpenAI client with Hugging Face's serverless API
|
11 |
client = OpenAI(
|
12 |
base_url="https://api-inference.huggingface.co/v1/",
|
13 |
api_key=ACCESS_TOKEN,
|
|
|
29 |
print(f"Received message: {message}")
|
30 |
print(f"History: {history}")
|
31 |
print(f"System message: {system_message}")
|
32 |
+
print(f"Max tokens: {max_tokens}, Temperature: {temperature}, Top-P: {top_p}")
|
33 |
+
print(f"Frequency penalty: {frequency_penalty}, Top-K: {top_k}, Seed: {seed}")
|
34 |
|
35 |
+
# Construct the messages list for the conversation context
|
36 |
messages = [{"role": "system", "content": system_message}]
|
37 |
|
38 |
for val in history:
|
|
|
66 |
|
67 |
print("Completed response generation.")
|
68 |
|
69 |
+
# Initialize the chatbot interface
|
70 |
chatbot = gr.Chatbot(height=600)
|
71 |
|
72 |
print("Chatbot interface created.")
|
73 |
|
74 |
+
# Create the Gradio interface with additional inputs for the new parameters
|
75 |
demo = gr.ChatInterface(
|
76 |
respond,
|
77 |
additional_inputs=[
|
|
|
86 |
label="Top-P",
|
87 |
),
|
88 |
gr.Slider(
|
89 |
+
minimum=-2.0,
|
90 |
maximum=2.0,
|
91 |
value=0.0,
|
92 |
step=0.1,
|
|
|
101 |
),
|
102 |
gr.Slider(
|
103 |
minimum=-1,
|
104 |
+
maximum=2**31 - 1,
|
105 |
value=-1,
|
106 |
step=1,
|
107 |
+
label="Seed",
|
108 |
),
|
109 |
],
|
110 |
fill_height=True,
|