Leonydis137 commited on
Commit
cc05a7c
·
verified ·
1 Parent(s): 5cde5c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -16
app.py CHANGED
@@ -1,8 +1,13 @@
1
-
2
  import streamlit as st
 
 
 
 
3
 
4
- st.title("Autonomous AI for Hugging Face Spaces")
 
5
 
 
6
  st.write("This AI can go online, diagnose itself, learn, and correct errors.")
7
 
8
  # Placeholder for system status
@@ -11,33 +16,66 @@ if 'status' not in st.session_state:
11
 
12
  st.write("System Status:", st.session_state['status'])
13
 
14
- # Buttons for control
15
- if st.button('Run Diagnostics'):
16
  st.session_state['status'] = 'Running Diagnostics...'
17
- # Call diagnostics function here
18
 
19
- if st.button('Self-Teach'):
20
  st.session_state['status'] = 'Learning...'
21
- # Call learning function here
22
 
23
- if st.button('Self-Correct'):
24
  st.session_state['status'] = 'Correcting Errors...'
25
- # Call correction function here
26
 
27
  st.write("Control Panel")
28
 
29
- import diagnostics
30
- import learning
31
- import correction
32
-
33
- if st.button('Run Diagnostics'):
34
  result = diagnostics.run_diagnostics()
35
  st.write('Diagnostics Result:', result)
36
 
37
- if st.button('Self-Teach'):
38
  result = learning.self_learn()
39
  st.write('Learning Result:', result)
40
 
41
- if st.button('Self-Correct'):
42
  result = correction.self_correct()
43
  st.write('Correction Result:', result)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import diagnostics
3
+ import learning
4
+ import correction
5
+ import requests, ast, traceback, logging, os, contextlib, io, json, time, re, sys
6
 
7
+ st.title("🎈 My new app")
8
+ st.write("Let's start building! For help and inspiration, head over to [docs.streamlit.io](https://docs.streamlit.io/).")
9
 
10
+ st.title("Autonomous AI for Hugging Face Spaces")
11
  st.write("This AI can go online, diagnose itself, learn, and correct errors.")
12
 
13
  # Placeholder for system status
 
16
 
17
  st.write("System Status:", st.session_state['status'])
18
 
19
+ # Buttons for control panel
20
+ if st.button('Run Diagnostics1', key="run_diag1"):
21
  st.session_state['status'] = 'Running Diagnostics...'
 
22
 
23
+ if st.button('Self-Teach1', key="self_teach1"):
24
  st.session_state['status'] = 'Learning...'
 
25
 
26
+ if st.button('Self-Correct1', key="self_correct1"):
27
  st.session_state['status'] = 'Correcting Errors...'
 
28
 
29
  st.write("Control Panel")
30
 
31
+ # Core actions
32
+ if st.button('Run Diagnostics', key="run_diag2"):
 
 
 
33
  result = diagnostics.run_diagnostics()
34
  st.write('Diagnostics Result:', result)
35
 
36
+ if st.button('Self-Teach', key="self_teach2"):
37
  result = learning.self_learn()
38
  st.write('Learning Result:', result)
39
 
40
+ if st.button('Self-Correct', key="self_correct2"):
41
  result = correction.self_correct()
42
  st.write('Correction Result:', result)
43
+ learning_result = learning.self_learn()
44
+ st.write('Learning Result:', learning_result)
45
+
46
+ if st.button('Self-Correct', key="self_correct3"):
47
+ result = correction.self_correct()
48
+ st.write('Correction Result:', result)
49
+
50
+ # Diagnostic log viewer
51
+ LOG_FILE = "ai_diagnostics.log"
52
+ FEEDBACK_FILE = "user_feedback.jsonl"
53
+ logging.basicConfig(filename=LOG_FILE, level=logging.INFO,
54
+ format="%(asctime)s - %(levelname)s - %(message)s")
55
+
56
+ def show_logs():
57
+ if not os.path.exists(LOG_FILE):
58
+ return 'No logs yet.'
59
+ with open(LOG_FILE) as f:
60
+ return ''.join(f.readlines()[-250:])
61
+
62
+ def save_feedback(text, rating):
63
+ with open(FEEDBACK_FILE, 'a') as f:
64
+ f.write(json.dumps({'time': time.time(), 'fb': text, 'rating': rating}) + '\n')
65
+ logging.info('Feedback stored')
66
+ return 'Thanks for the feedback!'
67
+
68
+ def self_diagnose():
69
+ try:
70
+ import py_compile
71
+ py_compile.compile(__file__, doraise=True)
72
+ return 'No syntax errors in current code.'
73
+ except py_compile.PyCompileError as e:
74
+ return 'Self-diagnose found syntax issue: ' + str(e)
75
+
76
+ # Optional diagnostics UI
77
+ if st.button("Run Self-Diagnostics", key="self_diag"):
78
+ st.write(self_diagnose())
79
+
80
+ if st.button("Show Logs", key="show_logs"):
81
+ st.text(show_logs())