kenken999 commited on
Commit
daeeecc
1 Parent(s): 7c8021a
Files changed (2) hide show
  1. babyagi/babyagi.py +186 -0
  2. mysite/routers/gradio.py +3 -3
babyagi/babyagi.py CHANGED
@@ -25,6 +25,84 @@ import torch
25
  import numpy
26
 
27
  import psycopg2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
  class ProductDatabase:
30
  def __init__(self, database_url):
@@ -771,6 +849,114 @@ def main():
771
  if __name__ == "__main__":
772
  main()
773
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
774
  def test_postgres():
775
  # データベース接続情報
776
  DATABASE_URL = "postgresql://miyataken999:yz1wPf4KrWTm@ep-odd-mode-93794521.us-east-2.aws.neon.tech/neondb?sslmode=require"
 
25
  import numpy
26
 
27
  import psycopg2
28
+ import shutil
29
+ import gradio as gr
30
+ from mysite.libs.utilities import chat_with_interpreter, completion, process_file
31
+ from interpreter import interpreter
32
+ import mysite.interpreter.interpreter_config # インポートするだけで設定が適用されます
33
+ import importlib
34
+ import os
35
+ import pkgutil
36
+ import async_timeout
37
+ import asyncio
38
+
39
+
40
+ DESCRIPTION = """
41
+ <div>
42
+ <h1 style="text-align: center;">develop site</h1>
43
+ <p>🦕 共同開発 AIシステム設定 LINE開発 CHATGPTS CHATGPTアシスタント設定 AI自動開発設定 APPSHEET GAS PYTHON</p>
44
+ </div>
45
+ <!-- Start of HubSpot Embed Code -->
46
+ <script type="text/javascript" id="hs-script-loader" async defer src="//js-na1.hs-scripts.com/46277896.js"></script>
47
+ <!-- End of HubSpot Embed Code -->
48
+ """
49
+
50
+ LICENSE = """
51
+ <p/>
52
+ <!-- Start of HubSpot Embed Code -->
53
+ <script type="text/javascript" id="hs-script-loader" async defer src="//js-na1.hs-scripts.com/46277896.js"></script>
54
+ <!-- End of HubSpot Embed Code -->
55
+ ---
56
+ Built with Meta Llama 3
57
+ """
58
+
59
+ PLACEHOLDER = """
60
+ <div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
61
+ <img src="https://ysharma-dummy-chat-app.hf.space/file=/tmp/gradio/8e75e61cc9bab22b7ce3dec85ab0e6db1da5d107/Meta_lockup_positive%20primary_RGB.jpg" style="width: 80%; max-width: 550px; height: auto; opacity: 0.55; ">
62
+ <h1 style="font-size: 28px; margin-bottom: 2px; opacity: 0.55;">Meta llama3</h1>
63
+ <p style="font-size: 18px; margin-bottom: 2px; opacity: 0.65;">Ask me anything...</p>
64
+ </div>
65
+ """
66
+
67
+
68
+ # チャットインターフェースの関数定義
69
+ # def chat_with_interpreter(message):
70
+ # return "Response: " + message
71
+
72
+
73
+ # カスタムCSSの定義
74
+ css = """
75
+ .gradio-container {
76
+ height: 100vh; /* 全体の高さを100vhに設定 */
77
+ display: flex;
78
+ flex-direction: column;
79
+ }
80
+ .gradio-tabs {
81
+ flex: 1; /* タブ全体の高さを最大に設定 */
82
+ display: flex;
83
+ flex-direction: column;
84
+ }
85
+ .gradio-tab-item {
86
+ flex: 1; /* 各タブの高さを最大に設定 */
87
+ display: flex;
88
+ flex-direction: column;
89
+ overflow: hidden; /* オーバーフローを隠す */
90
+ }
91
+ .gradio-block {
92
+ flex: 1; /* ブロックの高さを最大に設定 */
93
+ display: flex;
94
+ flex-direction: column;
95
+ }
96
+ .gradio-chatbot {
97
+ height: 100vh; /* チャットボットの高さを100vhに設定 */
98
+ overflow-y: auto; /* 縦スクロールを有効にする */
99
+ }
100
+ """
101
+ GENERATION_TIMEOUT_SEC = 60
102
+ # Gradio block
103
+ chatbot2 = gr.Chatbot(height=450, placeholder=PLACEHOLDER, label="Gradio ChatInterface")
104
+
105
+
106
 
107
  class ProductDatabase:
108
  def __init__(self, database_url):
 
849
  if __name__ == "__main__":
850
  main()
851
 
852
+
853
+ async def completion(message: str, history, c=None, d=None, prompt="あなたは日本語の優秀なアシスタントです。"):
854
+ OBJECTIVE = message
855
+ loop = True
856
+ while loop:
857
+ # As long as there are tasks in the storage...
858
+ if not tasks_storage.is_empty():
859
+ #OBJECTIVE = "ボットの性能をよくする方法 日本語で説明"
860
+ # Print the task list
861
+ print("\033[95m\033[1m" + "\n*****TASK LIST*****\n" + "\033[0m\033[0m")
862
+ for t in tasks_storage.get_task_names():
863
+ print(" • " + str(t))
864
+ result yield
865
+
866
+ # Step 1: Pull the first incomplete task
867
+ task = tasks_storage.popleft()
868
+ print("\033[92m\033[1m" + "\n*****NEXT TASK*****\n" + "\033[0m\033[0m")
869
+ print(str(task["task_name"]))
870
+ yield result
871
+
872
+ # Send to execution function to complete the task based on the context
873
+ result = execution_agent(OBJECTIVE, str(task["task_name"]))
874
+ print("\033[93m\033[1m" + "\n*****TASK RESULT*****\n" + "\033[0m\033[0m")
875
+ print(result)
876
+ yield result
877
+
878
+ # Step 2: Enrich result and store in the results storage
879
+ # This is where you should enrich the result if needed
880
+ enriched_result = {
881
+ "data": result
882
+ }
883
+ # extract the actual result from the dictionary
884
+ # since we don't do enrichment currently
885
+ vector = enriched_result["data"]
886
+
887
+ result_id = f"result_{task['task_id']}"
888
+
889
+ results_storage.add(task, result, result_id)
890
+
891
+ # Step 3: Create new tasks and re-prioritize task list
892
+ # only the main instance in cooperative mode does that
893
+ new_tasks = task_creation_agent(
894
+ OBJECTIVE,
895
+ enriched_result,
896
+ task["task_name"],
897
+ tasks_storage.get_task_names(),
898
+ )
899
+
900
+ print('Adding new tasks to task_storage')
901
+ for new_task in new_tasks:
902
+ new_task.update({"task_id": tasks_storage.next_task_id()})
903
+ print(str(new_task))
904
+ tasks_storage.append(new_task)
905
+
906
+ if not JOIN_EXISTING_OBJECTIVE:
907
+ prioritized_tasks = prioritization_agent()
908
+ if prioritized_tasks:
909
+ tasks_storage.replace(prioritized_tasks)
910
+
911
+ # Sleep a bit before checking the task list again
912
+ time.sleep(15)
913
+ else:
914
+ print('Done.')
915
+ loop = False
916
+
917
+
918
+
919
+
920
+ with gr.Blocks(fill_height=True, css=css) as gradio_babyagi:
921
+ # gr.Markdown(DESCRIPTION)
922
+ # gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
923
+ gr.ChatInterface(
924
+ fn=completion,
925
+ chatbot=chatbot2,
926
+ fill_height=True,
927
+ additional_inputs_accordion=gr.Accordion(
928
+ label="⚙️ Parameters", open=False, render=False
929
+ ),
930
+ additional_inputs=[
931
+ gr.Slider(
932
+ minimum=0,
933
+ maximum=1,
934
+ step=0.1,
935
+ value=0.95,
936
+ label="Temperature",
937
+ render=False,
938
+ ),
939
+ gr.Slider(
940
+ minimum=128,
941
+ maximum=4096,
942
+ step=1,
943
+ value=512,
944
+ label="Max new tokens",
945
+ render=False,
946
+ ),
947
+ ],
948
+ examples=[
949
+ ["HTMLのサンプルを作成して"],
950
+ [
951
+ "CUDA_VISIBLE_DEVICES=0 llamafactory-cli train examples/lora_single_gpu/llama3_lora_sft.yaml"
952
+ ],
953
+ ],
954
+ cache_examples=False,
955
+ )
956
+
957
+ gr.Markdown(LICENSE)
958
+
959
+
960
  def test_postgres():
961
  # データベース接続情報
962
  DATABASE_URL = "postgresql://miyataken999:yz1wPf4KrWTm@ep-odd-mode-93794521.us-east-2.aws.neon.tech/neondb?sslmode=require"
mysite/routers/gradio.py CHANGED
@@ -39,9 +39,9 @@ def include_gradio_interfaces():
39
 
40
  def setup_gradio_interfaces():
41
 
42
-
43
- default_interfaces = []#,demo]
44
- default_names = ["Chat","OpenInterpreter","DataBase","CreateFromDOC"]#"demo"]
45
 
46
  gradio_interfaces, gradio_names = include_gradio_interfaces()
47
 
 
39
 
40
  def setup_gradio_interfaces():
41
 
42
+ from babyagi.babyagi import gradio_babyagi
43
+ default_interfaces = [gradio_babyagi]#,demo]
44
+ default_names = ["Chat","OpenInterpreter","DataBase","CreateFromDOC","babyagi"]#"demo"]
45
 
46
  gradio_interfaces, gradio_names = include_gradio_interfaces()
47