Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,63 +1,74 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
from
|
|
|
4 |
|
5 |
-
# Initialize
|
6 |
ai_core = AICoreAGIX()
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
gr.
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
],
|
|
|
|
|
60 |
)
|
61 |
|
62 |
if __name__ == "__main__":
|
63 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import os
|
3 |
+
from HuggingFaceHelper import HuggingFaceHelper
|
4 |
+
from AICoreAGIX_with_TB import AICoreAGIX
|
5 |
|
6 |
+
# Initialize AI Core for TB analysis
|
7 |
ai_core = AICoreAGIX()
|
8 |
|
9 |
+
# Initialize Hugging Face training helper
|
10 |
+
helper = HuggingFaceHelper(model_path="./merged_model")
|
11 |
+
|
12 |
+
def diagnose_tb(image_file, audio_file):
|
13 |
+
user_id = 1 # Placeholder user ID
|
14 |
+
result = ai_core.run_tb_diagnostics(image_file.name, audio_file.name, user_id)
|
15 |
+
return (
|
16 |
+
f"**TB Risk Level:** {result['tb_risk']}\n\n"
|
17 |
+
f"**Image Result:** {result['image_analysis']['result']} "
|
18 |
+
f"(Confidence: {result['image_analysis']['confidence']:.2f})\n\n"
|
19 |
+
f"**Audio Result:** {result['audio_analysis']['result']} "
|
20 |
+
f"(Confidence: {result['audio_analysis']['confidence']:.2f})\n\n"
|
21 |
+
f"**Ethical Analysis:** {result['ethical_analysis']}\n\n"
|
22 |
+
f"**Explanation:** {result['explanation']}\n\n"
|
23 |
+
f"**Shareable Link:** {result['shareable_link']}"
|
24 |
+
)
|
25 |
+
|
26 |
+
def upload_and_finetune(jsonl_file):
|
27 |
+
save_path = f"./training_data/{jsonl_file.name}"
|
28 |
+
os.makedirs("training_data", exist_ok=True)
|
29 |
+
|
30 |
+
with open(save_path, "wb") as f:
|
31 |
+
f.write(jsonl_file.read())
|
32 |
+
|
33 |
+
# Trigger fine-tuning
|
34 |
+
helper.dataset_path = save_path
|
35 |
+
helper.fine_tune(output_dir="./codette_finetuned")
|
36 |
+
|
37 |
+
return f"â
Fine-tuning complete! Model updated and stored."
|
38 |
+
|
39 |
+
def get_latest_model():
|
40 |
+
return "Download the latest fine-tuned Codriao model here: https://huggingface.co/Raiff1982/codriao-finetuned"
|
41 |
+
|
42 |
+
# Gradio UI
|
43 |
+
demo = gr.TabbedInterface(
|
44 |
+
[
|
45 |
+
gr.Interface(
|
46 |
+
fn=diagnose_tb,
|
47 |
+
inputs=[
|
48 |
+
gr.File(label="Upload TB Saliva Image"),
|
49 |
+
gr.File(label="Upload Cough Audio File (.wav)")
|
50 |
+
],
|
51 |
+
outputs="text",
|
52 |
+
title="Codriao TB Risk Analyzer",
|
53 |
+
description="Upload a microscopy image and cough audio to analyze TB risk with compassionate AI support."
|
54 |
+
),
|
55 |
+
gr.Interface(
|
56 |
+
fn=upload_and_finetune,
|
57 |
+
inputs=[gr.File(label="Upload JSONL Training Data")],
|
58 |
+
outputs="text",
|
59 |
+
title="Codriao Fine-Tuning Trainer",
|
60 |
+
description="Upload JSONL files to teach Codriao new knowledge."
|
61 |
+
),
|
62 |
+
gr.Interface(
|
63 |
+
fn=get_latest_model,
|
64 |
+
inputs=[],
|
65 |
+
outputs="text",
|
66 |
+
title="Download Codriao's Fine-Tuned Model"
|
67 |
+
)
|
68 |
],
|
69 |
+
title="Codriao AI System",
|
70 |
+
description="Train Codriao, run TB diagnostics, and download updated models."
|
71 |
)
|
72 |
|
73 |
if __name__ == "__main__":
|
74 |
+
demo.launch()
|