Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,62 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
from
|
4 |
|
|
|
5 |
ai_core = AICoreAGIX()
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
],
|
30 |
-
outputs=gr.Markdown(label="Codriao's Response"),
|
31 |
-
title="Codriao TB Risk Analyzer",
|
32 |
-
description="Upload a microscopy image and cough audio to analyze TB risk with compassionate AI support."
|
33 |
)
|
34 |
|
35 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
+
from Codriaoagix import AICoreAGIX # Ensure this imports your AICoreAGIX class
|
4 |
|
5 |
+
# Initialize the AI core
|
6 |
ai_core = AICoreAGIX()
|
7 |
|
8 |
+
def respond(message, history, system_message, max_tokens, temperature, top_p, image, audio):
|
9 |
+
# Process the uploaded files
|
10 |
+
if image and audio:
|
11 |
+
# Save the uploaded files to disk or process them as needed
|
12 |
+
image_path = "uploaded_image.png"
|
13 |
+
audio_path = "uploaded_audio.wav"
|
14 |
+
image.save(image_path)
|
15 |
+
audio.save(audio_path)
|
16 |
+
|
17 |
+
# Run TB diagnostics
|
18 |
+
tb_result = ai_core.run_tb_diagnostics(image_path, audio_path, user_id=1) # Replace with actual user_id handling
|
19 |
+
|
20 |
+
# Incorporate TB diagnostic results into the response
|
21 |
+
tb_message = f"TB Diagnostic Result: {tb_result['tb_risk']}\n"
|
22 |
+
tb_message += f"Image Analysis: {tb_result['image_analysis']}\n"
|
23 |
+
tb_message += f"Audio Analysis: {tb_result['audio_analysis']}\n"
|
24 |
+
tb_message += f"Shareable Link: {tb_result['shareable_link']}\n\n"
|
25 |
+
else:
|
26 |
+
tb_message = "No TB diagnostic data provided.\n\n"
|
27 |
+
|
28 |
+
# Existing chat functionality
|
29 |
+
messages = [{"role": "system", "content": system_message}]
|
30 |
+
for user_msg, bot_msg in history:
|
31 |
+
if user_msg:
|
32 |
+
messages.append({"role": "user", "content": user_msg})
|
33 |
+
if bot_msg:
|
34 |
+
messages.append({"role": "assistant", "content": bot_msg})
|
35 |
+
messages.append({"role": "user", "content": message})
|
36 |
+
|
37 |
+
response = ""
|
38 |
+
for message in client.chat_completion(
|
39 |
+
messages,
|
40 |
+
max_tokens=max_tokens,
|
41 |
+
stream=True,
|
42 |
+
temperature=temperature,
|
43 |
+
top_p=top_p,
|
44 |
+
):
|
45 |
+
token = message.choices[0].delta.content
|
46 |
+
response += token
|
47 |
+
yield tb_message + response
|
48 |
+
|
49 |
+
# Define the Gradio interface
|
50 |
+
demo = gr.ChatInterface(
|
51 |
+
respond,
|
52 |
+
additional_inputs=[
|
53 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
54 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
55 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
56 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
57 |
+
gr.inputs.Image(type="pil", label="Upload Saliva Microscopy Image"),
|
58 |
+
gr.inputs.Audio(type="file", label="Upload Cough Audio Recording"),
|
59 |
],
|
|
|
|
|
|
|
60 |
)
|
61 |
|
62 |
if __name__ == "__main__":
|