Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,7 +25,7 @@ file_name = os.getenv("FILE_NAME")
|
|
| 25 |
|
| 26 |
############### CHAT ###################
|
| 27 |
def predict(user_input, history):
|
| 28 |
-
max_length =
|
| 29 |
transcript_file_path = f"{prefix}{coach_code}-{file_name}"
|
| 30 |
transcript = "" # Initialize the transcript variable
|
| 31 |
|
|
@@ -37,9 +37,10 @@ def predict(user_input, history):
|
|
| 37 |
transcript = file.read()
|
| 38 |
return transcript
|
| 39 |
except FileNotFoundError:
|
| 40 |
-
return "File '" +
|
| 41 |
elif len(user_input) > max_length:
|
| 42 |
-
|
|
|
|
| 43 |
|
| 44 |
history_openai_format = [
|
| 45 |
{"role": "system", "content": "IDENTITY: " + sys_prompt_new}
|
|
@@ -68,7 +69,7 @@ def predict(user_input, history):
|
|
| 68 |
pass
|
| 69 |
|
| 70 |
# Append latest user and assistant messages to the transcript
|
| 71 |
-
transcript += "Date/Time: " + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\n
|
| 72 |
transcript += f"YOU: {user_input}\n\n"
|
| 73 |
transcript += f"{coach_name_upper}: {message_content}\n\n\n"
|
| 74 |
# Write the updated transcript to the file
|
|
@@ -78,6 +79,6 @@ def predict(user_input, history):
|
|
| 78 |
return message_content
|
| 79 |
|
| 80 |
#GUI
|
| 81 |
-
with gr.Blocks(theme) as demo:
|
| 82 |
gr.ChatInterface(predict, submit_btn="Chat with "+ coach_name_short, retry_btn=None, undo_btn=None, clear_btn=None, autofocus=True)
|
| 83 |
demo.launch(show_api=False)
|
|
|
|
| 25 |
|
| 26 |
############### CHAT ###################
|
| 27 |
def predict(user_input, history):
|
| 28 |
+
max_length = 2000
|
| 29 |
transcript_file_path = f"{prefix}{coach_code}-{file_name}"
|
| 30 |
transcript = "" # Initialize the transcript variable
|
| 31 |
|
|
|
|
| 37 |
transcript = file.read()
|
| 38 |
return transcript
|
| 39 |
except FileNotFoundError:
|
| 40 |
+
return "File '" + file_name + "' not found."
|
| 41 |
elif len(user_input) > max_length:
|
| 42 |
+
user_input = ""
|
| 43 |
+
# raise gr.Error(f"Input is TOO LONG. Max length is {max_length} characters. Try again.")
|
| 44 |
|
| 45 |
history_openai_format = [
|
| 46 |
{"role": "system", "content": "IDENTITY: " + sys_prompt_new}
|
|
|
|
| 69 |
pass
|
| 70 |
|
| 71 |
# Append latest user and assistant messages to the transcript
|
| 72 |
+
transcript += "Date/Time: " + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\n"
|
| 73 |
transcript += f"YOU: {user_input}\n\n"
|
| 74 |
transcript += f"{coach_name_upper}: {message_content}\n\n\n"
|
| 75 |
# Write the updated transcript to the file
|
|
|
|
| 79 |
return message_content
|
| 80 |
|
| 81 |
#GUI
|
| 82 |
+
with gr.Blocks(theme, css="footer {visibility: hidden}") as demo:
|
| 83 |
gr.ChatInterface(predict, submit_btn="Chat with "+ coach_name_short, retry_btn=None, undo_btn=None, clear_btn=None, autofocus=True)
|
| 84 |
demo.launch(show_api=False)
|