Skip to content

Commit 5cb72cf

Browse files
committed
Refactor analysis workflow and improve result display
Updated the analysis function to handle both file and text inputs as bytes and refactored the engine.analyze call to use the correct parameters. Changed test and transform config formatting, removed threading for analysis execution, and added error handling. Improved result display by removing problematic 'metrics' column and enhanced visual rendering to support base64 and file path images with error handling.
1 parent 21c2b2a commit 5cb72cf

1 file changed

Lines changed: 44 additions & 11 deletions

File tree

app.py

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,19 @@
88
engine = Engine()
99

1010
def run_analysis(config):
11-
result = engine.analyze(config)
11+
# input_bytes'ı hesaplayalım
12+
input_bytes = b""
13+
if config.get('data', {}).get('file'):
14+
uploaded_file = config['data']['file']
15+
if uploaded_file is not None:
16+
input_bytes = uploaded_file.read()
17+
elif config.get('data', {}).get('text'):
18+
text = config['data']['text']
19+
if text:
20+
input_bytes = text.encode('utf-8')
21+
22+
# engine.analyze çağrısı doğru parametrelerle
23+
result = engine.analyze(input_bytes, config)
1224
st.session_state['analysis_result'] = result
1325

1426
def main():
@@ -69,12 +81,17 @@ def main():
6981
'file': st.session_state.uploaded_file,
7082
'text': st.session_state.text_input,
7183
},
72-
'tests': st.session_state.selected_tests,
73-
'transforms': st.session_state.selected_transforms,
84+
'tests': [{'name': t} for t in st.session_state.selected_tests],
85+
'transforms': [{'name': tr} for tr in st.session_state.selected_transforms],
7486
}
7587

7688
with st.spinner('Analiz yapılıyor...'):
77-
threading.Thread(target=run_analysis, args=(config,)).start()
89+
# Thread yerine direkt çağrı yapalım
90+
try:
91+
run_analysis(config)
92+
except Exception as e:
93+
st.error(f"Analiz hatası: {str(e)}")
94+
st.session_state['analysis_result'] = {"error": str(e)}
7895

7996
# Gösterim: Analiz sonucu session_state'te varsa ana ekranda göster
8097
if 'analysis_result' in st.session_state:
@@ -100,13 +117,16 @@ def main():
100117
st.subheader("Bulgular")
101118
if results:
102119
df = pd.DataFrame(results)
120+
# Metrics sütunu sorun çıkarabilir, onu çıkaralım
121+
if 'metrics' in df.columns:
122+
df = df.drop(columns=['metrics'])
103123
if 'p_value' in df.columns:
104124
def _p_style(v):
105125
try:
106126
return 'background-color: red' if float(v) < 0.05 else ''
107127
except Exception:
108128
return ''
109-
styled = df.style.applymap(_p_style, subset=['p_value'])
129+
styled = df.style.map(_p_style, subset=['p_value'])
110130
st.dataframe(styled)
111131
else:
112132
st.dataframe(df)
@@ -131,12 +151,25 @@ def _p_style(v):
131151
visuals = selected_result.get('visuals') if isinstance(selected_result, dict) else None
132152
if visuals:
133153
st.subheader("Görseller")
134-
for v in visuals:
135-
try:
136-
st.image(v, use_column_width=True)
137-
except Exception:
138-
# Eğer doğrudan gösterilemiyorsa base64 veya ham SVG olabilir; yine de dene
139-
st.image(v)
154+
for vname, vdata in visuals.items():
155+
if isinstance(vdata, dict):
156+
if 'data_base64' in vdata:
157+
try:
158+
import base64
159+
mime = vdata.get('mime', 'image/svg+xml')
160+
img_data = base64.b64decode(vdata['data_base64'])
161+
st.image(img_data, caption=vname, use_container_width=True)
162+
except Exception as e:
163+
st.error(f"Görsel gösterilemedi ({vname}): {str(e)}")
164+
elif 'path' in vdata:
165+
try:
166+
st.image(vdata['path'], caption=vname, use_column_width=True)
167+
except Exception as e:
168+
st.error(f"Görsel gösterilemedi ({vname}): {str(e)}")
169+
else:
170+
st.write(f"Görsel verisi tanınmıyor: {vname}")
171+
else:
172+
st.write(f"Görsel formatı yanlış: {vname}")
140173
else:
141174
st.info("Henüz analiz sonucu yok veya sonuç listesi boş.")
142175

0 commit comments

Comments
 (0)