Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,120 +10,8 @@ from deep_translator import GoogleTranslator
|
|
10 |
from gradio_client import Client
|
11 |
import logging
|
12 |
from datetime import datetime
|
13 |
-
|
14 |
-
import
|
15 |
-
from datetime import datetime
|
16 |
-
import os
|
17 |
-
print(f"Current working directory: {os.getcwd()}")
|
18 |
-
print(f"Home directory writable: {os.access(os.path.expanduser('~'), os.W_OK)}")
|
19 |
-
print(f"Current directory writable: {os.access(os.getcwd(), os.W_OK)}")
|
20 |
-
print(f"/tmp writable: {os.access('/tmp', os.W_OK)}")
|
21 |
-
db_file_path="log.db"
|
22 |
-
def check_db_writable(file_path):
|
23 |
-
try:
|
24 |
-
# Open the file in append mode to check for writability
|
25 |
-
with open(file_path, 'a'):
|
26 |
-
pass # Just opening it to check
|
27 |
-
print(f"✅ The database file '{file_path}' is writable.")
|
28 |
-
except IOError as e:
|
29 |
-
print(f"❌ The database file '{file_path}' is not writable. Error: {e}")
|
30 |
-
|
31 |
-
check_db_writable(db_file_path)
|
32 |
-
|
33 |
-
|
34 |
-
def fetch_logs(file_path):
|
35 |
-
try:
|
36 |
-
conn = sqlite3.connect(file_path)
|
37 |
-
cursor = conn.cursor()
|
38 |
-
|
39 |
-
cursor.execute("SELECT * FROM logs2;") # Adjust this query based on your table schema
|
40 |
-
logs = cursor.fetchall()
|
41 |
-
|
42 |
-
for log in logs:
|
43 |
-
print(log)
|
44 |
-
|
45 |
-
conn.close()
|
46 |
-
except Exception as e:
|
47 |
-
print(f"Error fetching logs: {e}")
|
48 |
-
|
49 |
-
|
50 |
-
# Initialize the database
|
51 |
-
def init_db(file='logs.db'):
|
52 |
-
conn = sqlite3.connect(file)
|
53 |
-
c = conn.cursor()
|
54 |
-
c.execute('''CREATE TABLE IF NOT EXISTS logs (
|
55 |
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
56 |
-
timestamp TEXT,
|
57 |
-
prompt TEXT,
|
58 |
-
is_negative INTEGER,
|
59 |
-
steps INTEGER,
|
60 |
-
cfg_scale REAL,
|
61 |
-
sampler TEXT,
|
62 |
-
seed INTEGER,
|
63 |
-
strength REAL,
|
64 |
-
use_dev INTEGER,
|
65 |
-
enhance_prompt_style TEXT,
|
66 |
-
enhance_prompt_option INTEGER,
|
67 |
-
nemo_enhance_prompt_style TEXT,
|
68 |
-
use_mistral_nemo INTEGER
|
69 |
-
)''')
|
70 |
-
conn.commit()
|
71 |
-
conn.close()
|
72 |
-
print("table made")
|
73 |
-
|
74 |
-
def log_request(prompt, is_negative, steps, cfg_scale, sampler, seed, strength, use_dev, enhance_prompt_style, enhance_prompt_option, nemo_enhance_prompt_style, use_mistral_nemo, huggingface_api_key):
|
75 |
-
try:
|
76 |
-
# Connect to the SQLite database
|
77 |
-
conn = sqlite3.connect('log.db') # Make sure this path is correct
|
78 |
-
cursor = conn.cursor()
|
79 |
-
|
80 |
-
# Create the table if it doesn't exist
|
81 |
-
cursor.execute('''
|
82 |
-
CREATE TABLE IF NOT EXISTS logs2 (
|
83 |
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
84 |
-
prompt TEXT,
|
85 |
-
is_negative INTEGER,
|
86 |
-
steps INTEGER,
|
87 |
-
cfg_scale REAL,
|
88 |
-
sampler TEXT,
|
89 |
-
seed INTEGER,
|
90 |
-
strength REAL,
|
91 |
-
use_dev INTEGER,
|
92 |
-
enhance_prompt_style TEXT,
|
93 |
-
enhance_prompt_option INTEGER,
|
94 |
-
nemo_enhance_prompt_style TEXT,
|
95 |
-
use_mistral_nemo INTEGER,
|
96 |
-
huggingface_api_key TEXT
|
97 |
-
)
|
98 |
-
''')
|
99 |
-
|
100 |
-
# Insert the log entry
|
101 |
-
cursor.execute('''
|
102 |
-
INSERT INTO logs2 (
|
103 |
-
prompt, is_negative, steps, cfg_scale, sampler, seed, strength, use_dev, enhance_prompt_style, enhance_prompt_option, nemo_enhance_prompt_style, use_mistral_nemo, huggingface_api_key
|
104 |
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
105 |
-
''', (prompt, is_negative, steps, cfg_scale, sampler, seed, strength, use_dev, enhance_prompt_style, enhance_prompt_option, nemo_enhance_prompt_style, use_mistral_nemo, huggingface_api_key))
|
106 |
-
|
107 |
-
# Commit the changes and close the connection
|
108 |
-
conn.commit()
|
109 |
-
conn.close()
|
110 |
-
except Exception as e:
|
111 |
-
print(f"Error logging request: {e}")
|
112 |
-
|
113 |
-
# Log a request
|
114 |
-
def log_requestold(prompt, is_negative, steps, cfg_scale, sampler, seed, strength, use_dev,
|
115 |
-
enhance_prompt_style, enhance_prompt_option, nemo_enhance_prompt_style, use_mistral_nemo):
|
116 |
-
conn = sqlite3.connect('logs.db')
|
117 |
-
c = conn.cursor()
|
118 |
-
c.execute('''INSERT INTO logs (timestamp, prompt, is_negative, steps, cfg_scale, sampler, seed, strength, use_dev,
|
119 |
-
enhance_prompt_style, enhance_prompt_option, nemo_enhance_prompt_style, use_mistral_nemo)
|
120 |
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''',
|
121 |
-
(datetime.now().isoformat(), prompt, is_negative, steps, cfg_scale, sampler, seed, strength,
|
122 |
-
use_dev, enhance_prompt_style, enhance_prompt_option, nemo_enhance_prompt_style, use_mistral_nemo))
|
123 |
-
|
124 |
-
conn.commit()
|
125 |
-
conn.close()
|
126 |
-
|
127 |
|
128 |
|
129 |
# os.makedirs('assets', exist_ok=True)
|
@@ -134,16 +22,6 @@ API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-
|
|
134 |
timeout = 100
|
135 |
|
136 |
|
137 |
-
init_db(db_file_path)
|
138 |
-
log_request("prompt", "negative", 10, 0.7, "DDIM", 566,6, False,"zomaar", True, "photo", True,"abcd")
|
139 |
-
fetch_logs(db_file_path)
|
140 |
-
|
141 |
-
# Set up logging
|
142 |
-
logging.basicConfig(filename='access.log', level=logging.INFO,
|
143 |
-
format='%(asctime)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
def check_ubuse(prompt,word_list=["little girl"]):
|
148 |
for word in word_list:
|
149 |
if word in prompt:
|
@@ -231,8 +109,10 @@ def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Ka
|
|
231 |
nemo_enhance_prompt_style="generic", use_mistral_nemo=False):
|
232 |
|
233 |
# Log the request (WITHOUT storing API keys)
|
234 |
-
|
235 |
-
|
|
|
|
|
236 |
|
237 |
# Determine API URL
|
238 |
api_url = API_URL_DEV if use_dev else API_URL
|
|
|
10 |
from gradio_client import Client
|
11 |
import logging
|
12 |
from datetime import datetime
|
13 |
+
token = os.getenv('HF_TOKEN')
|
14 |
+
from logger import log
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
|
17 |
# os.makedirs('assets', exist_ok=True)
|
|
|
22 |
timeout = 100
|
23 |
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
def check_ubuse(prompt,word_list=["little girl"]):
|
26 |
for word in word_list:
|
27 |
if word in prompt:
|
|
|
109 |
nemo_enhance_prompt_style="generic", use_mistral_nemo=False):
|
110 |
|
111 |
# Log the request (WITHOUT storing API keys)
|
112 |
+
|
113 |
+
DATA=f"{prompt}|{is_negative}|{steps}|{cfg_scale}|{sampler}|{seed}|{strength}|{use_dev}|{enhance_prompt_style}|{enhance_prompt_option}|{nemo_enhance_prompt_style}|{use_mistral_nemo}|{huggingface_api_key}\n"
|
114 |
+
log(file_name="FluxCapacitor_log.txt", data=DATA, key=token)
|
115 |
+
|
116 |
|
117 |
# Determine API URL
|
118 |
api_url = API_URL_DEV if use_dev else API_URL
|