Upload 2 files
Browse files- huggingface_int V2.py +31 -0
- requirements.txt +3 -0
huggingface_int V2.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Load the tokenizer and model directly
|
6 |
+
model_name = "ruslanmv/ai-medical-model-32bit"
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
9 |
+
model.to("cuda") # Move model to GPU
|
10 |
+
|
11 |
+
|
12 |
+
# Function to ask medical questions
|
13 |
+
def ask_medical_question(question):
|
14 |
+
prompt = f"<|start_header_id|>system<|end_header_id|> You are a Medical AI chatbot assistant. <|eot_id|><|start_header_id|>User: <|end_header_id|>This is the question: {question}<|eot_id|>"
|
15 |
+
|
16 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
17 |
+
outputs = model.generate(
|
18 |
+
**inputs,
|
19 |
+
max_new_tokens=256,
|
20 |
+
temperature=0.7,
|
21 |
+
do_sample=True,
|
22 |
+
top_p=0.95,
|
23 |
+
top_k=50,
|
24 |
+
)
|
25 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
26 |
+
return response
|
27 |
+
|
28 |
+
|
29 |
+
# Set up Gradio interface
|
30 |
+
iface = gr.Interface(fn=ask_medical_question, inputs="text", outputs="text")
|
31 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
transformers
|
3 |
+
torch
|