File size: 1,846 Bytes
c9599d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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()