Spaces:
Sleeping
Sleeping
Rajan Sharma
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,9 +23,10 @@ def format_system_info():
|
|
| 23 |
@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=10))
|
| 24 |
def initialize_model():
|
| 25 |
try:
|
| 26 |
-
|
|
|
|
| 27 |
if not token:
|
| 28 |
-
return False, "No token found. Please set HUGGING_FACE_HUB_TOKEN in Space secrets.", None
|
| 29 |
|
| 30 |
# Force re-login to refresh connection
|
| 31 |
login(token=token, add_to_git_credential=False)
|
|
@@ -94,7 +95,7 @@ def chat(message, history):
|
|
| 94 |
|
| 95 |
def check_connection():
|
| 96 |
try:
|
| 97 |
-
token = os.getenv("HUGGING_FACE_HUB_TOKEN")
|
| 98 |
api = HfApi(token=token)
|
| 99 |
model_info = api.model_info("CohereLabs/c4ai-command-a-03-2025")
|
| 100 |
return f"""
|
|
@@ -108,7 +109,7 @@ Last Modified: {model_info.lastModified}
|
|
| 108 |
|
| 109 |
# Create the Gradio interface with connection monitoring
|
| 110 |
with gr.Blocks(theme=gr.themes.Default()) as demo:
|
| 111 |
-
gr.Markdown(f"# Medical Decision Support AI")
|
| 112 |
|
| 113 |
with gr.Row():
|
| 114 |
connection_btn = gr.Button("Check Connection Status")
|
|
@@ -116,13 +117,13 @@ with gr.Blocks(theme=gr.themes.Default()) as demo:
|
|
| 116 |
|
| 117 |
chat_interface = gr.ChatInterface(
|
| 118 |
fn=chat,
|
| 119 |
-
description="A medical decision support system that provides healthcare-related information and guidance
|
| 120 |
examples=[
|
| 121 |
"What are the symptoms of hypertension?",
|
| 122 |
"What are common drug interactions with aspirin?",
|
| 123 |
"What are the warning signs of diabetes?",
|
| 124 |
],
|
| 125 |
-
type='messages' #
|
| 126 |
)
|
| 127 |
|
| 128 |
connection_btn.click(check_connection, outputs=connection_status)
|
|
|
|
| 23 |
@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=10))
|
| 24 |
def initialize_model():
|
| 25 |
try:
|
| 26 |
+
# Try HUGGING_FACE_HUB_TOKEN first, fallback to HF_TOKEN
|
| 27 |
+
token = os.getenv("HUGGING_FACE_HUB_TOKEN") or os.getenv("HF_TOKEN")
|
| 28 |
if not token:
|
| 29 |
+
return False, "No token found. Please set HUGGING_FACE_HUB_TOKEN or HF_TOKEN in Space secrets.", None
|
| 30 |
|
| 31 |
# Force re-login to refresh connection
|
| 32 |
login(token=token, add_to_git_credential=False)
|
|
|
|
| 95 |
|
| 96 |
def check_connection():
|
| 97 |
try:
|
| 98 |
+
token = os.getenv("HUGGING_FACE_HUB_TOKEN") or os.getenv("HF_TOKEN")
|
| 99 |
api = HfApi(token=token)
|
| 100 |
model_info = api.model_info("CohereLabs/c4ai-command-a-03-2025")
|
| 101 |
return f"""
|
|
|
|
| 109 |
|
| 110 |
# Create the Gradio interface with connection monitoring
|
| 111 |
with gr.Blocks(theme=gr.themes.Default()) as demo:
|
| 112 |
+
gr.Markdown(f"# Medical Decision Support AI\n{format_system_info()}")
|
| 113 |
|
| 114 |
with gr.Row():
|
| 115 |
connection_btn = gr.Button("Check Connection Status")
|
|
|
|
| 117 |
|
| 118 |
chat_interface = gr.ChatInterface(
|
| 119 |
fn=chat,
|
| 120 |
+
description=f"A medical decision support system that provides healthcare-related information and guidance.\n{format_system_info()}",
|
| 121 |
examples=[
|
| 122 |
"What are the symptoms of hypertension?",
|
| 123 |
"What are common drug interactions with aspirin?",
|
| 124 |
"What are the warning signs of diabetes?",
|
| 125 |
],
|
| 126 |
+
type='messages' # Using new message format
|
| 127 |
)
|
| 128 |
|
| 129 |
connection_btn.click(check_connection, outputs=connection_status)
|