Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
import sys
|
|
|
4 |
sys.path.append("/home/user/app") # Ensures Hugging Face looks in the correct place
|
|
|
5 |
from HuggingFaceHelper import HuggingFaceHelper
|
6 |
from AICoreAGIX_with_TB import AICoreAGIX
|
7 |
|
@@ -9,11 +11,23 @@ from AICoreAGIX_with_TB import AICoreAGIX
|
|
9 |
ai_core = AICoreAGIX()
|
10 |
|
11 |
# Initialize Hugging Face training helper
|
12 |
-
helper = HuggingFaceHelper(model_path="
|
13 |
|
14 |
-
def
|
15 |
user_id = 1 # Placeholder user ID
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
return (
|
18 |
f"**TB Risk Level:** {result['tb_risk']}\n\n"
|
19 |
f"**Image Result:** {result['image_analysis']['result']} "
|
@@ -25,7 +39,13 @@ def diagnose_tb(image_file, audio_file):
|
|
25 |
f"**Shareable Link:** {result['shareable_link']}"
|
26 |
)
|
27 |
|
|
|
|
|
|
|
28 |
def upload_and_finetune(jsonl_file):
|
|
|
|
|
|
|
29 |
save_path = f"./training_data/{jsonl_file.name}"
|
30 |
os.makedirs("training_data", exist_ok=True)
|
31 |
|
@@ -36,7 +56,12 @@ def upload_and_finetune(jsonl_file):
|
|
36 |
helper.dataset_path = save_path
|
37 |
helper.fine_tune(output_dir="./codette_finetuned")
|
38 |
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
def get_latest_model():
|
42 |
return "Download the latest fine-tuned Codriao model here: https://huggingface.co/Raiff1982/codriao-finetuned"
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
import sys
|
4 |
+
import asyncio
|
5 |
sys.path.append("/home/user/app") # Ensures Hugging Face looks in the correct place
|
6 |
+
|
7 |
from HuggingFaceHelper import HuggingFaceHelper
|
8 |
from AICoreAGIX_with_TB import AICoreAGIX
|
9 |
|
|
|
11 |
ai_core = AICoreAGIX()
|
12 |
|
13 |
# Initialize Hugging Face training helper
|
14 |
+
helper = HuggingFaceHelper(model_path="Raiff1982/codriao-finetuned")
|
15 |
|
16 |
+
async def diagnose_tb_async(image_file, audio_file):
|
17 |
user_id = 1 # Placeholder user ID
|
18 |
+
|
19 |
+
if image_file is None or audio_file is None:
|
20 |
+
return "Please upload both a TB saliva image and a cough audio file."
|
21 |
+
|
22 |
+
result = await ai_core.run_tb_diagnostics(image_file.name, audio_file.name, user_id)
|
23 |
+
|
24 |
+
# Optional file cleanup
|
25 |
+
try:
|
26 |
+
os.remove(image_file.name)
|
27 |
+
os.remove(audio_file.name)
|
28 |
+
except:
|
29 |
+
pass
|
30 |
+
|
31 |
return (
|
32 |
f"**TB Risk Level:** {result['tb_risk']}\n\n"
|
33 |
f"**Image Result:** {result['image_analysis']['result']} "
|
|
|
39 |
f"**Shareable Link:** {result['shareable_link']}"
|
40 |
)
|
41 |
|
42 |
+
def diagnose_tb(image_file, audio_file):
|
43 |
+
return asyncio.run(diagnose_tb_async(image_file, audio_file))
|
44 |
+
|
45 |
def upload_and_finetune(jsonl_file):
|
46 |
+
if jsonl_file is None:
|
47 |
+
return "Please upload a .jsonl file to fine-tune Codriao."
|
48 |
+
|
49 |
save_path = f"./training_data/{jsonl_file.name}"
|
50 |
os.makedirs("training_data", exist_ok=True)
|
51 |
|
|
|
56 |
helper.dataset_path = save_path
|
57 |
helper.fine_tune(output_dir="./codette_finetuned")
|
58 |
|
59 |
+
try:
|
60 |
+
os.remove(save_path)
|
61 |
+
except:
|
62 |
+
pass
|
63 |
+
|
64 |
+
return "â
Fine-tuning complete! Model updated and stored."
|
65 |
|
66 |
def get_latest_model():
|
67 |
return "Download the latest fine-tuned Codriao model here: https://huggingface.co/Raiff1982/codriao-finetuned"
|