Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,10 +4,10 @@ from openai import OpenAI
|
|
| 4 |
from typing import List, Tuple
|
| 5 |
|
| 6 |
ENDPOINT_URL = "https://api.hyperbolic.xyz/v1"
|
| 7 |
-
|
| 8 |
OAI_API_KEY = os.getenv('HYPERBOLIC_XYZ_KEY')
|
|
|
|
| 9 |
|
| 10 |
-
client = OpenAI(base_url=ENDPOINT_URL,api_key=OAI_API_KEY)
|
| 11 |
|
| 12 |
def respond(
|
| 13 |
message: str,
|
|
@@ -17,19 +17,14 @@ def respond(
|
|
| 17 |
temperature: float,
|
| 18 |
top_p: float,
|
| 19 |
):
|
| 20 |
-
# Prepare the conversation history
|
| 21 |
messages = [{"role": "system", "content": system_message}]
|
| 22 |
-
|
| 23 |
for user_msg, assistant_msg in history:
|
| 24 |
if user_msg:
|
| 25 |
messages.append({"role": "user", "content": user_msg})
|
| 26 |
if assistant_msg:
|
| 27 |
messages.append({"role": "assistant", "content": assistant_msg})
|
| 28 |
-
|
| 29 |
-
# Add the latest user message
|
| 30 |
messages.append({"role": "user", "content": message})
|
| 31 |
|
| 32 |
-
# Stream the response from OpenAI
|
| 33 |
response = ""
|
| 34 |
for chunk in client.chat.completions.create(
|
| 35 |
model="deepseek-ai/DeepSeek-V3",
|
|
@@ -43,24 +38,34 @@ def respond(
|
|
| 43 |
response += token
|
| 44 |
yield response
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
value=0.95,
|
| 58 |
-
step=0.05,
|
| 59 |
-
label="Top-p (nucleus sampling)",
|
| 60 |
-
),
|
| 61 |
-
],
|
| 62 |
-
)
|
| 63 |
|
|
|
|
| 64 |
|
| 65 |
if __name__ == "__main__":
|
| 66 |
-
demo.launch(share=True
|
|
|
|
| 4 |
from typing import List, Tuple
|
| 5 |
|
| 6 |
ENDPOINT_URL = "https://api.hyperbolic.xyz/v1"
|
|
|
|
| 7 |
OAI_API_KEY = os.getenv('HYPERBOLIC_XYZ_KEY')
|
| 8 |
+
PASSWORD = os.getenv("PASSWD") # Store the password in an environment variable
|
| 9 |
|
| 10 |
+
client = OpenAI(base_url=ENDPOINT_URL, api_key=OAI_API_KEY)
|
| 11 |
|
| 12 |
def respond(
|
| 13 |
message: str,
|
|
|
|
| 17 |
temperature: float,
|
| 18 |
top_p: float,
|
| 19 |
):
|
|
|
|
| 20 |
messages = [{"role": "system", "content": system_message}]
|
|
|
|
| 21 |
for user_msg, assistant_msg in history:
|
| 22 |
if user_msg:
|
| 23 |
messages.append({"role": "user", "content": user_msg})
|
| 24 |
if assistant_msg:
|
| 25 |
messages.append({"role": "assistant", "content": assistant_msg})
|
|
|
|
|
|
|
| 26 |
messages.append({"role": "user", "content": message})
|
| 27 |
|
|
|
|
| 28 |
response = ""
|
| 29 |
for chunk in client.chat.completions.create(
|
| 30 |
model="deepseek-ai/DeepSeek-V3",
|
|
|
|
| 38 |
response += token
|
| 39 |
yield response
|
| 40 |
|
| 41 |
+
def check_password(input_password):
|
| 42 |
+
if input_password == PASSWORD:
|
| 43 |
+
return gr.update(visible=False), gr.update(visible=True)
|
| 44 |
+
else:
|
| 45 |
+
return gr.update(value="", interactive=True), gr.update(visible=False)
|
| 46 |
+
|
| 47 |
+
with gr.Blocks() as demo:
|
| 48 |
+
with gr.Column():
|
| 49 |
+
password_input = gr.Textbox(
|
| 50 |
+
type="password", label="Enter Password", interactive=True
|
| 51 |
+
)
|
| 52 |
+
submit_button = gr.Button("Submit")
|
| 53 |
+
error_message = gr.Textbox(
|
| 54 |
+
label="Error", visible=False, interactive=False
|
| 55 |
+
)
|
| 56 |
|
| 57 |
+
with gr.Column(visible=False) as chat_interface:
|
| 58 |
+
chat = gr.ChatInterface(
|
| 59 |
+
respond,
|
| 60 |
+
additional_inputs=[
|
| 61 |
+
gr.Textbox(value="You are a helpful assistant.", label="System message"),
|
| 62 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 63 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 64 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
| 65 |
+
],
|
| 66 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
+
submit_button.click(check_password, inputs=password_input, outputs=[password_input, chat_interface])
|
| 69 |
|
| 70 |
if __name__ == "__main__":
|
| 71 |
+
demo.launch(share=True)
|