Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- chatgpt.py +26 -17
chatgpt.py
CHANGED
@@ -12,8 +12,8 @@ from interview_protocol import protocols as interview_protocols
|
|
12 |
|
13 |
model = whisper.load_model("base")
|
14 |
|
15 |
-
base_url = "https://llm4socialisolation-fd4082d0a518.herokuapp.com"
|
16 |
-
|
17 |
|
18 |
timeout = 60
|
19 |
|
@@ -82,10 +82,13 @@ async def get_backend_response(api_key, patient_prompt, username, chatbot_type):
|
|
82 |
except Exception as e:
|
83 |
return f"Error contacting backend service: {str(e)}"
|
84 |
|
85 |
-
async def save_conversation_and_memory(username):
|
86 |
url = f"{base_url}/save/end_and_save"
|
87 |
headers = {'Content-Type': 'application/json'}
|
88 |
-
data = {
|
|
|
|
|
|
|
89 |
async with httpx.AsyncClient(timeout=timeout) as client:
|
90 |
try:
|
91 |
response = await client.post(url, json=data, headers=headers)
|
@@ -97,10 +100,13 @@ async def save_conversation_and_memory(username):
|
|
97 |
except Exception as e:
|
98 |
return f"Error contacting backend service: {str(e)}"
|
99 |
|
100 |
-
async def get_conversation_histories(username):
|
101 |
url = f"{base_url}/save/download_conversations"
|
102 |
headers = {'Content-Type': 'application/json'}
|
103 |
-
data = {
|
|
|
|
|
|
|
104 |
async with httpx.AsyncClient(timeout=timeout) as client:
|
105 |
try:
|
106 |
response = await client.post(url, json=data, headers=headers)
|
@@ -112,8 +118,8 @@ async def get_conversation_histories(username):
|
|
112 |
except Exception as e:
|
113 |
return []
|
114 |
|
115 |
-
def download_conversations(username):
|
116 |
-
conversation_histories = asyncio.run(get_conversation_histories(username))
|
117 |
files = []
|
118 |
temp_dir = tempfile.mkdtemp()
|
119 |
for conversation_entry in conversation_histories:
|
@@ -132,10 +138,13 @@ def download_conversations(username):
|
|
132 |
files.append(temp_file_path)
|
133 |
return files
|
134 |
|
135 |
-
async def get_biography(username):
|
136 |
url = f"{base_url}/save/generate_autobiography"
|
137 |
headers = {'Content-Type': 'application/json'}
|
138 |
-
data = {
|
|
|
|
|
|
|
139 |
async with httpx.AsyncClient(timeout=timeout) as client:
|
140 |
try:
|
141 |
response = await client.post(url, json=data, headers=headers)
|
@@ -148,8 +157,8 @@ async def get_biography(username):
|
|
148 |
except Exception as e:
|
149 |
return f"Error contacting backend service: {str(e)}"
|
150 |
|
151 |
-
def download_biography(username):
|
152 |
-
biography_text = asyncio.run(get_biography(username))
|
153 |
if not biography_text or "Failed" in biography_text or "Error" in biography_text:
|
154 |
return gr.update(value=None, visible=False), biography_text
|
155 |
temp_dir = tempfile.mkdtemp()
|
@@ -187,8 +196,8 @@ def set_initialize_button(api_key_input, chapter_name, topic_name, username_inpu
|
|
187 |
print(message)
|
188 |
return message, api_key_input
|
189 |
|
190 |
-
def save_conversation(username):
|
191 |
-
response = asyncio.run(save_conversation_and_memory(username))
|
192 |
return response
|
193 |
|
194 |
def start_recording(audio_file):
|
@@ -390,19 +399,19 @@ with gr.Blocks() as app:
|
|
390 |
|
391 |
download_button.click(
|
392 |
fn=download_conversations,
|
393 |
-
inputs=[username_input],
|
394 |
outputs=gr.Files()
|
395 |
)
|
396 |
|
397 |
download_biography_button.click(
|
398 |
fn=download_biography,
|
399 |
-
inputs=[username_input],
|
400 |
outputs=[gr.File(label="Biography.txt"), gr.Textbox(visible=False)]
|
401 |
)
|
402 |
|
403 |
save_conversation_button.click(
|
404 |
fn=save_conversation,
|
405 |
-
inputs=[username_input],
|
406 |
outputs=None
|
407 |
)
|
408 |
|
|
|
12 |
|
13 |
model = whisper.load_model("base")
|
14 |
|
15 |
+
# base_url = "https://llm4socialisolation-fd4082d0a518.herokuapp.com"
|
16 |
+
base_url = "http://localhost:8080"
|
17 |
|
18 |
timeout = 60
|
19 |
|
|
|
82 |
except Exception as e:
|
83 |
return f"Error contacting backend service: {str(e)}"
|
84 |
|
85 |
+
async def save_conversation_and_memory(username, chatbot_type):
|
86 |
url = f"{base_url}/save/end_and_save"
|
87 |
headers = {'Content-Type': 'application/json'}
|
88 |
+
data = {
|
89 |
+
'username': username,
|
90 |
+
'chatbot_type': chatbot_type
|
91 |
+
}
|
92 |
async with httpx.AsyncClient(timeout=timeout) as client:
|
93 |
try:
|
94 |
response = await client.post(url, json=data, headers=headers)
|
|
|
100 |
except Exception as e:
|
101 |
return f"Error contacting backend service: {str(e)}"
|
102 |
|
103 |
+
async def get_conversation_histories(username, chatbot_type):
|
104 |
url = f"{base_url}/save/download_conversations"
|
105 |
headers = {'Content-Type': 'application/json'}
|
106 |
+
data = {
|
107 |
+
'username': username,
|
108 |
+
'chatbot_type': chatbot_type
|
109 |
+
}
|
110 |
async with httpx.AsyncClient(timeout=timeout) as client:
|
111 |
try:
|
112 |
response = await client.post(url, json=data, headers=headers)
|
|
|
118 |
except Exception as e:
|
119 |
return []
|
120 |
|
121 |
+
def download_conversations(username, chatbot_type):
|
122 |
+
conversation_histories = asyncio.run(get_conversation_histories(username, chatbot_type))
|
123 |
files = []
|
124 |
temp_dir = tempfile.mkdtemp()
|
125 |
for conversation_entry in conversation_histories:
|
|
|
138 |
files.append(temp_file_path)
|
139 |
return files
|
140 |
|
141 |
+
async def get_biography(username, chatbot_type):
|
142 |
url = f"{base_url}/save/generate_autobiography"
|
143 |
headers = {'Content-Type': 'application/json'}
|
144 |
+
data = {
|
145 |
+
'username': username,
|
146 |
+
'chatbot_type': chatbot_type
|
147 |
+
}
|
148 |
async with httpx.AsyncClient(timeout=timeout) as client:
|
149 |
try:
|
150 |
response = await client.post(url, json=data, headers=headers)
|
|
|
157 |
except Exception as e:
|
158 |
return f"Error contacting backend service: {str(e)}"
|
159 |
|
160 |
+
def download_biography(username, chatbot_type):
|
161 |
+
biography_text = asyncio.run(get_biography(username, chatbot_type))
|
162 |
if not biography_text or "Failed" in biography_text or "Error" in biography_text:
|
163 |
return gr.update(value=None, visible=False), biography_text
|
164 |
temp_dir = tempfile.mkdtemp()
|
|
|
196 |
print(message)
|
197 |
return message, api_key_input
|
198 |
|
199 |
+
def save_conversation(username, chatbot_type):
|
200 |
+
response = asyncio.run(save_conversation_and_memory(username, chatbot_type))
|
201 |
return response
|
202 |
|
203 |
def start_recording(audio_file):
|
|
|
399 |
|
400 |
download_button.click(
|
401 |
fn=download_conversations,
|
402 |
+
inputs=[username_input, chatbot_type_state],
|
403 |
outputs=gr.Files()
|
404 |
)
|
405 |
|
406 |
download_biography_button.click(
|
407 |
fn=download_biography,
|
408 |
+
inputs=[username_input, chatbot_type_state],
|
409 |
outputs=[gr.File(label="Biography.txt"), gr.Textbox(visible=False)]
|
410 |
)
|
411 |
|
412 |
save_conversation_button.click(
|
413 |
fn=save_conversation,
|
414 |
+
inputs=[username_input, chatbot_type_state],
|
415 |
outputs=None
|
416 |
)
|
417 |
|