Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
# INSTRUCTIONS for Chat Bot on line 42, Repository name on line 24
|
| 2 |
-
|
| 3 |
# Imports
|
| 4 |
import gradio as gr
|
| 5 |
from openai import OpenAI
|
|
@@ -7,6 +6,7 @@ import os
|
|
| 7 |
from github import Github
|
| 8 |
import uuid
|
| 9 |
import time
|
|
|
|
| 10 |
|
| 11 |
# Environment variables
|
| 12 |
openai_key = os.getenv("OPENAI_KEY")
|
|
@@ -88,13 +88,17 @@ with gr.Blocks(theme=gr.themes.Monochrome(), css="""footer {display:none !import
|
|
| 88 |
|
| 89 |
return formatted_chat, ""
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
# Generate Chat Bot response
|
| 92 |
def predict_prompt(user_id):
|
| 93 |
if not user_id or user_id not in user_dictionary:
|
| 94 |
return []
|
| 95 |
|
| 96 |
# Optional delay for a realistic human response time
|
| 97 |
-
time.sleep(1)
|
| 98 |
|
| 99 |
# Try to get the response from OpenAI
|
| 100 |
try:
|
|
@@ -152,7 +156,11 @@ with gr.Blocks(theme=gr.themes.Monochrome(), css="""footer {display:none !import
|
|
| 152 |
outputs=[Chatbot, txt],
|
| 153 |
queue=False
|
| 154 |
).then(
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
inputs=[user_id],
|
| 157 |
outputs=Chatbot
|
| 158 |
)
|
|
|
|
| 1 |
# INSTRUCTIONS for Chat Bot on line 42, Repository name on line 24
|
|
|
|
| 2 |
# Imports
|
| 3 |
import gradio as gr
|
| 4 |
from openai import OpenAI
|
|
|
|
| 6 |
from github import Github
|
| 7 |
import uuid
|
| 8 |
import time
|
| 9 |
+
import random # Added random to make the delay feel more human
|
| 10 |
|
| 11 |
# Environment variables
|
| 12 |
openai_key = os.getenv("OPENAI_KEY")
|
|
|
|
| 88 |
|
| 89 |
return formatted_chat, ""
|
| 90 |
|
| 91 |
+
# New Function: Simulates the time it takes the "person" to read your message (NO BUBBLES)
|
| 92 |
+
def pause_before_typing():
|
| 93 |
+
time.sleep(random.uniform(1.5, 3.0))
|
| 94 |
+
|
| 95 |
# Generate Chat Bot response
|
| 96 |
def predict_prompt(user_id):
|
| 97 |
if not user_id or user_id not in user_dictionary:
|
| 98 |
return []
|
| 99 |
|
| 100 |
# Optional delay for a realistic human response time
|
| 101 |
+
time.sleep(random.uniform(1.0, 2.5))
|
| 102 |
|
| 103 |
# Try to get the response from OpenAI
|
| 104 |
try:
|
|
|
|
| 156 |
outputs=[Chatbot, txt],
|
| 157 |
queue=False
|
| 158 |
).then(
|
| 159 |
+
pause_before_typing, # Added step: Sleeps before updating chatbot
|
| 160 |
+
inputs=None,
|
| 161 |
+
outputs=None
|
| 162 |
+
).then(
|
| 163 |
+
predict_prompt, # Final step: Triggers bubbles and gets response
|
| 164 |
inputs=[user_id],
|
| 165 |
outputs=Chatbot
|
| 166 |
)
|