Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -13,9 +13,11 @@ from threading import Lock
|
|
13 |
@dataclass
|
14 |
class AppState:
|
15 |
conversation: list = field(default_factory=list)
|
16 |
-
lock: Lock = field(default_factory=Lock)
|
17 |
client: openai.OpenAI = None
|
18 |
|
|
|
|
|
|
|
19 |
def create_client(api_key):
|
20 |
return openai.OpenAI(
|
21 |
base_url="https://llama3-1-8b.lepton.run/api/v1/",
|
@@ -68,7 +70,7 @@ def generate_response_and_audio(message, state):
|
|
68 |
if state.client is None:
|
69 |
raise gr.Error("Please enter a valid API key first.")
|
70 |
|
71 |
-
with
|
72 |
state.conversation.append({"role": "user", "content": message})
|
73 |
|
74 |
try:
|
|
|
13 |
@dataclass
|
14 |
class AppState:
|
15 |
conversation: list = field(default_factory=list)
|
|
|
16 |
client: openai.OpenAI = None
|
17 |
|
18 |
+
# Global lock for thread safety
|
19 |
+
state_lock = Lock()
|
20 |
+
|
21 |
def create_client(api_key):
|
22 |
return openai.OpenAI(
|
23 |
base_url="https://llama3-1-8b.lepton.run/api/v1/",
|
|
|
70 |
if state.client is None:
|
71 |
raise gr.Error("Please enter a valid API key first.")
|
72 |
|
73 |
+
with state_lock:
|
74 |
state.conversation.append({"role": "user", "content": message})
|
75 |
|
76 |
try:
|