Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ from github import Github
|
|
| 5 |
import uuid
|
| 6 |
|
| 7 |
openai.api_key = os.getenv('OPENAI_KEY')
|
| 8 |
-
|
| 9 |
# Create UI using gradio
|
| 10 |
with gr.Blocks(theme=gr.themes.Monochrome(),css="footer{display:none !important}") as chatblock:
|
| 11 |
message_history = []
|
|
@@ -20,8 +20,6 @@ with gr.Blocks(theme=gr.themes.Monochrome(),css="footer{display:none !important}
|
|
| 20 |
return gr.Markdown(f"<h1><center> Session Id: {new_id} </center></h1>",visible=True)
|
| 21 |
|
| 22 |
# Adding the instructions to the message history in the content dictionary for the ChatBot to understand.
|
| 23 |
-
instructions = 'You only speak in the form of periods and spaces. For example: "... .. .. ..... . ..."'
|
| 24 |
-
message_history.append({"role": "developer", "content": instructions})
|
| 25 |
|
| 26 |
# Message for User Interface
|
| 27 |
initial_message = "Please write your prompt here and press 'enter'"
|
|
@@ -33,7 +31,7 @@ with gr.Blocks(theme=gr.themes.Monochrome(),css="footer{display:none !important}
|
|
| 33 |
message_history.append({"role": "user", "content": input})
|
| 34 |
create_prompt = openai.ChatCompletion.create(
|
| 35 |
model = "gpt-4o",
|
| 36 |
-
messages = message_history
|
| 37 |
)
|
| 38 |
|
| 39 |
# Reply content for the chat bot
|
|
@@ -41,7 +39,7 @@ with gr.Blocks(theme=gr.themes.Monochrome(),css="footer{display:none !important}
|
|
| 41 |
|
| 42 |
# Append answer as assistant reply to keep history of prompts
|
| 43 |
message_history.append({"role": "assistant", "content": reply_prompt})
|
| 44 |
-
response = [(message_history[i]["content"], message_history[i+1]["content"]) for i in range(1, len(message_history)
|
| 45 |
|
| 46 |
# variable content store each message found in the message history and states the respective user. This is for the content to add in the file
|
| 47 |
content = ''
|
|
|
|
| 5 |
import uuid
|
| 6 |
|
| 7 |
openai.api_key = os.getenv('OPENAI_KEY')
|
| 8 |
+
|
| 9 |
# Create UI using gradio
|
| 10 |
with gr.Blocks(theme=gr.themes.Monochrome(),css="footer{display:none !important}") as chatblock:
|
| 11 |
message_history = []
|
|
|
|
| 20 |
return gr.Markdown(f"<h1><center> Session Id: {new_id} </center></h1>",visible=True)
|
| 21 |
|
| 22 |
# Adding the instructions to the message history in the content dictionary for the ChatBot to understand.
|
|
|
|
|
|
|
| 23 |
|
| 24 |
# Message for User Interface
|
| 25 |
initial_message = "Please write your prompt here and press 'enter'"
|
|
|
|
| 31 |
message_history.append({"role": "user", "content": input})
|
| 32 |
create_prompt = openai.ChatCompletion.create(
|
| 33 |
model = "gpt-4o",
|
| 34 |
+
messages = message_history,
|
| 35 |
)
|
| 36 |
|
| 37 |
# Reply content for the chat bot
|
|
|
|
| 39 |
|
| 40 |
# Append answer as assistant reply to keep history of prompts
|
| 41 |
message_history.append({"role": "assistant", "content": reply_prompt})
|
| 42 |
+
response = [(message_history[i]["content"], message_history[i+1]["content"]) for i in range(1, len(message_history)-1, 2)]
|
| 43 |
|
| 44 |
# variable content store each message found in the message history and states the respective user. This is for the content to add in the file
|
| 45 |
content = ''
|