Spaces:
Runtime error
Runtime error
Commit
·
e5f673c
1
Parent(s):
fd55770
update file func
Browse files
app.py
CHANGED
|
@@ -483,7 +483,7 @@ async def start_playwright(question: str):
|
|
| 483 |
langchain.debug = True
|
| 484 |
|
| 485 |
global memory3
|
| 486 |
-
memory3 = ConversationBufferWindowMemory(memory_key="chat_history", return_messages=True)
|
| 487 |
|
| 488 |
global memory2
|
| 489 |
memory2 = ConversationBufferWindowMemory(memory_key="chat_history")
|
|
@@ -536,11 +536,12 @@ LOADER_MAPPING = {
|
|
| 536 |
|
| 537 |
source_directory = 'Upload Files'
|
| 538 |
global file_list_loaded
|
| 539 |
-
file_list_loaded =
|
| 540 |
chunk_size = 500
|
| 541 |
chunk_overlap = 300
|
| 542 |
|
| 543 |
-
|
|
|
|
| 544 |
|
| 545 |
global Filename_Chatbot
|
| 546 |
Filename_Chatbot = ""
|
|
@@ -785,7 +786,7 @@ def text_to_speech_2(text):
|
|
| 785 |
response.raise_for_status()
|
| 786 |
timestr = time.strftime("%Y%m%d-%H%M%S")
|
| 787 |
with open('sample-' + timestr + '.wav', 'wb') as audio:
|
| 788 |
-
|
| 789 |
print ("File Name ", audio.name)
|
| 790 |
# print (audio)
|
| 791 |
Audio_output.append(audio.name)
|
|
@@ -1002,10 +1003,11 @@ When you are clear about the request, you can start to answer the request by **w
|
|
| 1002 |
When you need information, you can use tools as below and merge all gathered information from different tools.
|
| 1003 |
When you need to use "Code Runner" for code running, **Always recap the plan between each code block** (you have extreme short-term memory loss, so you need to recap the plan between each message block to retain it).
|
| 1004 |
When you send a message containing code to "Code Runner", it will be executed **on the user's machine**. The user has given you **full and complete permission** to execute any code necessary to complete the task. You have full access to control their computer to help them. Code entered into "Code Runner" will be executed **in the users local environment**.
|
| 1005 |
-
If you want to send data between programming languages, save the data to a txt or json.
|
| 1006 |
You can access the internet. Run **any code** to achieve the goal, and if at first you don't succeed, try again and again.
|
| 1007 |
You can install new packages with pip. Try to install all necessary packages in one command at the beginning.
|
| 1008 |
When a user refers to a filename, they're likely referring to an existing file in the directory you're currently in ("Code Runner" executes on the user's machine).
|
|
|
|
| 1009 |
In general, choose packages that have the most universal chance to be already installed and to work across multiple applications. Packages like ffmpeg and pandoc that are well-supported and powerful.
|
| 1010 |
Write messages to the user in Markdown. When the final answer has output files, you must output the **name** of the file.
|
| 1011 |
You are capable of **any** task.
|
|
@@ -1141,7 +1143,7 @@ prompt_openai = OpenAIMultiFunctionsAgent.create_prompt(
|
|
| 1141 |
)
|
| 1142 |
|
| 1143 |
input_variables=["input", "chat_history", "agent_scratchpad"]
|
| 1144 |
-
|
| 1145 |
|
| 1146 |
agent_ZEROSHOT_REACT = initialize_agent(tools2, llm,
|
| 1147 |
# agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
|
@@ -1198,7 +1200,7 @@ agent_STRUCTURED_ZEROSHOT_REACT = initialize_agent(tools_remote, GPTfake,
|
|
| 1198 |
'format_instructions': FORMAT_INSTRUCTIONS_STRUC,
|
| 1199 |
# 'suffix': SUFFIX2,
|
| 1200 |
"memory_prompts": [MessagesPlaceholder(variable_name="chat_history")],
|
| 1201 |
-
'input_variables':
|
| 1202 |
|
| 1203 |
},
|
| 1204 |
# input_variables = input_variables,
|
|
@@ -1473,6 +1475,23 @@ def Summary_upload_file(files, chat_history2):
|
|
| 1473 |
yield chat_history2
|
| 1474 |
|
| 1475 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1476 |
class Logger:
|
| 1477 |
def __init__(self, filename):
|
| 1478 |
self.terminal = sys.stdout
|
|
@@ -1528,7 +1547,9 @@ def chathmi3(message, history2):
|
|
| 1528 |
yield ["", history2]
|
| 1529 |
try:
|
| 1530 |
if agent is not None:
|
| 1531 |
-
response = agent.run(message)
|
|
|
|
|
|
|
| 1532 |
elif agent is None:
|
| 1533 |
response = asyncio.run(start_playwright(message))
|
| 1534 |
time.sleep(0.1)
|
|
@@ -1615,7 +1636,10 @@ def chathmi4(message, history2):
|
|
| 1615 |
try:
|
| 1616 |
if agent is not None:
|
| 1617 |
|
| 1618 |
-
response = agent.run(message)
|
|
|
|
|
|
|
|
|
|
| 1619 |
# test callback
|
| 1620 |
|
| 1621 |
# temp = []
|
|
@@ -1941,14 +1965,12 @@ def UpdateChatbot(Running_history):
|
|
| 1941 |
# # Running_history = Running_history + [(None, 'Timestamp: '+timestr)]
|
| 1942 |
# # yield Running_history
|
| 1943 |
WelcomeStr = """
|
| 1944 |
-
This is AI Assistant powered by MECH Core Team.
|
| 1945 |
-
It is connected remotely with GPT4. The following function is available for you.
|
| 1946 |
1. Free Chat with AI assistant
|
| 1947 |
2. Search Information and Engineering Data: Vector Database + Internet
|
| 1948 |
-
3. Make specific task with tools:
|
| 1949 |
-
|
| 1950 |
-
|
| 1951 |
-
- Text to Image (forecast)
|
| 1952 |
"""
|
| 1953 |
Running_history = Running_history + [(None, timestr+'\n'+WelcomeStr)]
|
| 1954 |
# ChatbotHistory = ChatbotHistory + [(None, timestr+'\n'+WelcomeStr)]
|
|
@@ -2066,12 +2088,13 @@ with gr.Blocks() as demo:
|
|
| 2066 |
# UserRecord.append((None, timestr+'\n'+WelcomeStr))
|
| 2067 |
with gr.Column() as main2:
|
| 2068 |
title = gr.Markdown("""# <center> STLA BABY - YOUR FRIENDLY GUIDE
|
| 2069 |
-
<center> v0.7.
|
| 2070 |
chatbot = gr.Chatbot(
|
| 2071 |
# avatar_images=((os.path.join(os.path.dirname(__file__),"User.png")), (os.path.join(os.path.dirname(__file__),"AI.png"))),
|
| 2072 |
)
|
| 2073 |
|
| 2074 |
with gr.Row():
|
|
|
|
| 2075 |
inputtext = gr.Textbox(
|
| 2076 |
scale= 4,
|
| 2077 |
label="",
|
|
@@ -2124,7 +2147,7 @@ with gr.Blocks() as demo:
|
|
| 2124 |
"""
|
| 2125 |
GUI Func
|
| 2126 |
"""
|
| 2127 |
-
|
| 2128 |
# upload_button.upload(func_upload_file, [upload_button, main.chatbot], main.chatbot)
|
| 2129 |
chatbot.like(vote, None, None)
|
| 2130 |
retry_button.click(retry, chatbot, chatbot).success(playsound1, None, voice_output).\
|
|
|
|
| 483 |
langchain.debug = True
|
| 484 |
|
| 485 |
global memory3
|
| 486 |
+
memory3 = ConversationBufferWindowMemory(memory_key="chat_history", input_key="input", output_key='output', return_messages=True)
|
| 487 |
|
| 488 |
global memory2
|
| 489 |
memory2 = ConversationBufferWindowMemory(memory_key="chat_history")
|
|
|
|
| 536 |
|
| 537 |
source_directory = 'Upload Files'
|
| 538 |
global file_list_loaded
|
| 539 |
+
file_list_loaded = []
|
| 540 |
chunk_size = 500
|
| 541 |
chunk_overlap = 300
|
| 542 |
|
| 543 |
+
global file_list_by_user
|
| 544 |
+
file_list_by_user = []
|
| 545 |
|
| 546 |
global Filename_Chatbot
|
| 547 |
Filename_Chatbot = ""
|
|
|
|
| 786 |
response.raise_for_status()
|
| 787 |
timestr = time.strftime("%Y%m%d-%H%M%S")
|
| 788 |
with open('sample-' + timestr + '.wav', 'wb') as audio:
|
| 789 |
+
audio.write(response.content)
|
| 790 |
print ("File Name ", audio.name)
|
| 791 |
# print (audio)
|
| 792 |
Audio_output.append(audio.name)
|
|
|
|
| 1003 |
When you need information, you can use tools as below and merge all gathered information from different tools.
|
| 1004 |
When you need to use "Code Runner" for code running, **Always recap the plan between each code block** (you have extreme short-term memory loss, so you need to recap the plan between each message block to retain it).
|
| 1005 |
When you send a message containing code to "Code Runner", it will be executed **on the user's machine**. The user has given you **full and complete permission** to execute any code necessary to complete the task. You have full access to control their computer to help them. Code entered into "Code Runner" will be executed **in the users local environment**.
|
| 1006 |
+
If you want to send data between programming languages, save the data to a txt or json. You should finish each step and output the result with the text content.
|
| 1007 |
You can access the internet. Run **any code** to achieve the goal, and if at first you don't succeed, try again and again.
|
| 1008 |
You can install new packages with pip. Try to install all necessary packages in one command at the beginning.
|
| 1009 |
When a user refers to a filename, they're likely referring to an existing file in the directory you're currently in ("Code Runner" executes on the user's machine).
|
| 1010 |
+
When a user refers to a uploaded file, they're likely referring to an existing file in {file_list_by_user}
|
| 1011 |
In general, choose packages that have the most universal chance to be already installed and to work across multiple applications. Packages like ffmpeg and pandoc that are well-supported and powerful.
|
| 1012 |
Write messages to the user in Markdown. When the final answer has output files, you must output the **name** of the file.
|
| 1013 |
You are capable of **any** task.
|
|
|
|
| 1143 |
)
|
| 1144 |
|
| 1145 |
input_variables=["input", "chat_history", "agent_scratchpad"]
|
| 1146 |
+
input_variables_2=["input", "chat_history", "agent_scratchpad", "file_list_by_user"]
|
| 1147 |
|
| 1148 |
agent_ZEROSHOT_REACT = initialize_agent(tools2, llm,
|
| 1149 |
# agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
|
|
|
| 1200 |
'format_instructions': FORMAT_INSTRUCTIONS_STRUC,
|
| 1201 |
# 'suffix': SUFFIX2,
|
| 1202 |
"memory_prompts": [MessagesPlaceholder(variable_name="chat_history")],
|
| 1203 |
+
'input_variables': input_variables_2,
|
| 1204 |
|
| 1205 |
},
|
| 1206 |
# input_variables = input_variables,
|
|
|
|
| 1475 |
yield chat_history2
|
| 1476 |
|
| 1477 |
|
| 1478 |
+
def User_Upload_file(files, chat_history2):
|
| 1479 |
+
global file_list_by_user
|
| 1480 |
+
file_list_by_user = []
|
| 1481 |
+
for unit in files:
|
| 1482 |
+
file_list_by_user.append(unit.name)
|
| 1483 |
+
# file_list_loaded = files
|
| 1484 |
+
print(file_list_by_user)
|
| 1485 |
+
# print(chat_history)
|
| 1486 |
+
# test_msg = ["Request Upload File into DB", "Operation Ongoing...."]
|
| 1487 |
+
|
| 1488 |
+
chat_history2 = chat_history2 + [("Updated Files:\n", None)]
|
| 1489 |
+
yield chat_history2
|
| 1490 |
+
# chat_history.append(test_msg)
|
| 1491 |
+
for file in files:
|
| 1492 |
+
chat_history2 = chat_history2 + [((file.name,), None)]
|
| 1493 |
+
yield chat_history2
|
| 1494 |
+
|
| 1495 |
class Logger:
|
| 1496 |
def __init__(self, filename):
|
| 1497 |
self.terminal = sys.stdout
|
|
|
|
| 1547 |
yield ["", history2]
|
| 1548 |
try:
|
| 1549 |
if agent is not None:
|
| 1550 |
+
# response = agent.run(message)
|
| 1551 |
+
temp = agent({'file_list_by_user':file_list_by_user, 'input': message})
|
| 1552 |
+
response = temp['output']
|
| 1553 |
elif agent is None:
|
| 1554 |
response = asyncio.run(start_playwright(message))
|
| 1555 |
time.sleep(0.1)
|
|
|
|
| 1636 |
try:
|
| 1637 |
if agent is not None:
|
| 1638 |
|
| 1639 |
+
# response = agent.run(message)
|
| 1640 |
+
temp = agent({'file_list_by_user':file_list_by_user, 'input': message})
|
| 1641 |
+
response = temp['output']
|
| 1642 |
+
# print("chathmi4 response:", response)
|
| 1643 |
# test callback
|
| 1644 |
|
| 1645 |
# temp = []
|
|
|
|
| 1965 |
# # Running_history = Running_history + [(None, 'Timestamp: '+timestr)]
|
| 1966 |
# # yield Running_history
|
| 1967 |
WelcomeStr = """
|
| 1968 |
+
This is AI Assistant powered by MECH Core Team and it is connected remotely with GPT4. The following function is available for you.
|
|
|
|
| 1969 |
1. Free Chat with AI assistant
|
| 1970 |
2. Search Information and Engineering Data: Vector Database + Internet
|
| 1971 |
+
3. Make specific task with tools: Text to Sound | Sound to Text | Doc summary
|
| 1972 |
+
4. Code interpret: very powerful to modify/create/analyze documents (90%)
|
| 1973 |
+
5. Text to Image | Image to Text: (forecast)
|
|
|
|
| 1974 |
"""
|
| 1975 |
Running_history = Running_history + [(None, timestr+'\n'+WelcomeStr)]
|
| 1976 |
# ChatbotHistory = ChatbotHistory + [(None, timestr+'\n'+WelcomeStr)]
|
|
|
|
| 2088 |
# UserRecord.append((None, timestr+'\n'+WelcomeStr))
|
| 2089 |
with gr.Column() as main2:
|
| 2090 |
title = gr.Markdown("""# <center> STLA BABY - YOUR FRIENDLY GUIDE
|
| 2091 |
+
<center> v0.7.12: Powered by MECH Core Team - GPT4 REMOTE MODE"""),
|
| 2092 |
chatbot = gr.Chatbot(
|
| 2093 |
# avatar_images=((os.path.join(os.path.dirname(__file__),"User.png")), (os.path.join(os.path.dirname(__file__),"AI.png"))),
|
| 2094 |
)
|
| 2095 |
|
| 2096 |
with gr.Row():
|
| 2097 |
+
AddFile_button = gr.UploadButton("⤴️ File", file_count="multiple", scale= 0, variant="secondary",size='sm')
|
| 2098 |
inputtext = gr.Textbox(
|
| 2099 |
scale= 4,
|
| 2100 |
label="",
|
|
|
|
| 2147 |
"""
|
| 2148 |
GUI Func
|
| 2149 |
"""
|
| 2150 |
+
AddFile_button.upload(User_Upload_file, [AddFile_button, chatbot], chatbot)
|
| 2151 |
# upload_button.upload(func_upload_file, [upload_button, main.chatbot], main.chatbot)
|
| 2152 |
chatbot.like(vote, None, None)
|
| 2153 |
retry_button.click(retry, chatbot, chatbot).success(playsound1, None, voice_output).\
|