Spaces:
Running
Running
import gradio as gr | |
import requests | |
import json | |
# Your HF token - in production, use environment variables | |
HF_TOKEN = "hf_your_token_here" | |
MODEL_ID = "Intelligent-Internet/II-Medical-32B-Preview" | |
def query_medical_model(question): | |
API_URL = f"https://api-inference.huggingface.co/models/{MODEL_ID}" | |
headers = { | |
"Authorization": f"Bearer {HF_TOKEN}", | |
"Content-Type": "application/json" | |
} | |
prompt = f"Please reason step-by-step about: {question}. Put your final answer within \\boxed{{}}." | |
payload = { | |
"inputs": prompt, | |
"parameters": { | |
"temperature": 0.6, | |
"top_p": 0.9, | |
"max_new_tokens": 1000, | |
"return_full_text": False | |
} | |
} | |
try: | |
response = requests.post(API_URL, headers=headers, json=payload) | |
if response.status_code == 200: | |
result = response.json() | |
if isinstance(result, list) and len(result) > 0: | |
return result[0].get('generated_text', 'No response generated') | |
else: | |
return str(result) | |
else: | |
return f"Error: {response.status_code} - {response.text}" | |
except Exception as e: | |
return f"Error: {str(e)}" | |
# Create Gradio interface | |
iface = gr.Interface( | |
fn=query_medical_model, | |
inputs=gr.Textbox(lines=3, placeholder="Enter your medical question here..."), | |
outputs=gr.Textbox(lines=10), | |
title="II-Medical-32B Medical Reasoning Assistant", | |
description="Ask medical questions and get step-by-step reasoning (For educational purposes only)", | |
examples=[ | |
"What are the symptoms of type 2 diabetes?", | |
"Explain the pathophysiology of heart failure", | |
"What are the diagnostic criteria for hypertension?" | |
] | |
) | |
if __name__ == "__main__": | |
iface.launch() |