Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import json
|
4 |
+
|
5 |
+
# Your HF token - in production, use environment variables
|
6 |
+
HF_TOKEN = "hf_your_token_here"
|
7 |
+
MODEL_ID = "Intelligent-Internet/II-Medical-32B-Preview"
|
8 |
+
|
9 |
+
def query_medical_model(question):
|
10 |
+
API_URL = f"https://api-inference.huggingface.co/models/{MODEL_ID}"
|
11 |
+
|
12 |
+
headers = {
|
13 |
+
"Authorization": f"Bearer {HF_TOKEN}",
|
14 |
+
"Content-Type": "application/json"
|
15 |
+
}
|
16 |
+
|
17 |
+
prompt = f"Please reason step-by-step about: {question}. Put your final answer within \\boxed{{}}."
|
18 |
+
|
19 |
+
payload = {
|
20 |
+
"inputs": prompt,
|
21 |
+
"parameters": {
|
22 |
+
"temperature": 0.6,
|
23 |
+
"top_p": 0.9,
|
24 |
+
"max_new_tokens": 1000,
|
25 |
+
"return_full_text": False
|
26 |
+
}
|
27 |
+
}
|
28 |
+
|
29 |
+
try:
|
30 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
31 |
+
if response.status_code == 200:
|
32 |
+
result = response.json()
|
33 |
+
if isinstance(result, list) and len(result) > 0:
|
34 |
+
return result[0].get('generated_text', 'No response generated')
|
35 |
+
else:
|
36 |
+
return str(result)
|
37 |
+
else:
|
38 |
+
return f"Error: {response.status_code} - {response.text}"
|
39 |
+
except Exception as e:
|
40 |
+
return f"Error: {str(e)}"
|
41 |
+
|
42 |
+
# Create Gradio interface
|
43 |
+
iface = gr.Interface(
|
44 |
+
fn=query_medical_model,
|
45 |
+
inputs=gr.Textbox(lines=3, placeholder="Enter your medical question here..."),
|
46 |
+
outputs=gr.Textbox(lines=10),
|
47 |
+
title="II-Medical-32B Medical Reasoning Assistant",
|
48 |
+
description="Ask medical questions and get step-by-step reasoning (For educational purposes only)",
|
49 |
+
examples=[
|
50 |
+
"What are the symptoms of type 2 diabetes?",
|
51 |
+
"Explain the pathophysiology of heart failure",
|
52 |
+
"What are the diagnostic criteria for hypertension?"
|
53 |
+
]
|
54 |
+
)
|
55 |
+
|
56 |
+
if __name__ == "__main__":
|
57 |
+
iface.launch()
|