Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Load your model and tokenizer
|
6 |
+
model_name = "Amir230703/phi3-medmcqa-finetuned"
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")
|
9 |
+
|
10 |
+
# Define function for inference
|
11 |
+
def generate_response(prompt):
|
12 |
+
input_ids = tokenizer(prompt, return_tensors="pt").input_ids
|
13 |
+
with torch.no_grad():
|
14 |
+
output = model.generate(input_ids, max_length=200)
|
15 |
+
return tokenizer.decode(output[0], skip_special_tokens=True)
|
16 |
+
|
17 |
+
# Create Gradio UI
|
18 |
+
iface = gr.Interface(
|
19 |
+
fn=generate_response,
|
20 |
+
inputs="text",
|
21 |
+
outputs="text",
|
22 |
+
title="Medical QA Model",
|
23 |
+
description="Enter a medical question, and the AI will provide an answer."
|
24 |
+
)
|
25 |
+
|
26 |
+
iface.launch()
|