Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,49 +1,18 @@
|
|
| 1 |
-
# -*- coding: utf-8 -*-
|
| 2 |
-
"""Load Model and Run Gradio - llama.ipynb
|
| 3 |
-
|
| 4 |
-
Automatically generated by Colab.
|
| 5 |
-
|
| 6 |
-
Original file is located at
|
| 7 |
-
https://colab.research.google.com/drive/1IQ2EW-KFfdkxEL8sZSfXA0WcS7ZHVPIf
|
| 8 |
-
"""
|
| 9 |
-
|
| 10 |
import os
|
| 11 |
token=os.environ['token']
|
| 12 |
-
# !pip install gradio --quiet
|
| 13 |
-
# !pip install requests --quiet
|
| 14 |
-
# !pip install -Uq xformers --index-url https://download.pytorch.org/whl/cu121
|
| 15 |
-
|
| 16 |
import torch
|
| 17 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
# For getting tokenizer()
|
| 20 |
model_id = "meta-llama/Meta-Llama-3-8B-Instruct"
|
| 21 |
peft_model_adapter_id = "nttwt1597/test_v2_cancer_v3"
|
| 22 |
|
| 23 |
-
# model_directory = "./model/"
|
| 24 |
-
|
| 25 |
-
# device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 26 |
-
# print("Using:", device)
|
| 27 |
-
|
| 28 |
-
#Commented out IPython magic to ensure Python compatibility.
|
| 29 |
-
#%%capture
|
| 30 |
-
# major_version, minor_version = torch.cuda.get_device_capability()
|
| 31 |
-
# Must install separately since Colab has torch 2.2.1, which breaks packages
|
| 32 |
-
#!pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
|
| 33 |
-
# if major_version >= 8:
|
| 34 |
-
# # Use this for new GPUs like Ampere, Hopper GPUs (RTX 30xx, RTX 40xx, A100, H100, L40)
|
| 35 |
-
# !pip install --no-deps packaging ninja einops flash-attn xformers trl peft accelerate bitsandbytes
|
| 36 |
-
# else:
|
| 37 |
-
# # Use this for older GPUs (V100, Tesla T4, RTX 20xx)
|
| 38 |
-
# !pip install --no-deps xformers trl peft accelerate bitsandbytes
|
| 39 |
-
# pass
|
| 40 |
-
|
| 41 |
-
# cuda 12.1 version
|
| 42 |
-
from unsloth import FastLanguageModel
|
| 43 |
-
from peft import PeftConfig, PeftModel, get_peft_model
|
| 44 |
-
|
| 45 |
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 46 |
-
model_name = model_id,
|
| 47 |
max_seq_length = 4096,
|
| 48 |
dtype = None,
|
| 49 |
load_in_4bit = True,
|
|
@@ -55,10 +24,7 @@ terminators = [
|
|
| 55 |
tokenizer.convert_tokens_to_ids("<|eot_id|>")
|
| 56 |
]
|
| 57 |
|
| 58 |
-
FastLanguageModel.for_inference(model)
|
| 59 |
-
|
| 60 |
-
from transformers import pipeline, TextIteratorStreamer
|
| 61 |
-
from threading import Thread
|
| 62 |
|
| 63 |
criteria_prompt = """Based on the provided instructions and clinical trial information, generate the eligibility criteria for the study.
|
| 64 |
|
|
@@ -90,45 +56,41 @@ def run_model_on_text(text):
|
|
| 90 |
yield generated_text
|
| 91 |
|
| 92 |
place_holder = f"""Study Objectives
|
| 93 |
-
|
| 94 |
|
| 95 |
-
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
|
|
|
| 99 |
|
| 100 |
-
|
| 101 |
-
Diagnostic Test: Near Focus NBI
|
| 102 |
-
Diagnostic Test: Standard Focus NBI
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
Phase: Not Applicable
|
| 110 |
-
Primary Purpose: Diagnostic
|
| 111 |
-
Allocation: Randomized
|
| 112 |
-
Interventional Model: Parallel Assignment
|
| 113 |
-
Masking: None (Open Label)
|
| 114 |
"""
|
| 115 |
|
| 116 |
prefilled_value = """Study Objectives
|
| 117 |
[Brief Summary] and/or [Detailed Description]
|
| 118 |
|
| 119 |
-
Conditions
|
| 120 |
|
| 121 |
Intervention / Treatment
|
|
|
|
| 122 |
|
| 123 |
Location
|
|
|
|
| 124 |
|
| 125 |
Study Design and Phases
|
| 126 |
-
Study Type
|
| 127 |
-
Phase
|
| 128 |
-
Primary Purpose
|
| 129 |
-
Allocation
|
| 130 |
-
Interventional Model
|
| 131 |
-
Masking"""
|
| 132 |
|
| 133 |
prompt_box = gr.Textbox(
|
| 134 |
lines=25,
|
|
@@ -149,4 +111,4 @@ demo = gr.Interface(
|
|
| 149 |
allow_flagging='auto',
|
| 150 |
)
|
| 151 |
|
| 152 |
-
demo.queue(max_size=20).launch(debug=True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
token=os.environ['token']
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import torch
|
| 4 |
import gradio as gr
|
| 5 |
+
from unsloth import FastLanguageModel
|
| 6 |
+
from peft import PeftConfig, PeftModel, get_peft_model
|
| 7 |
+
from transformers import pipeline, TextIteratorStreamer
|
| 8 |
+
from threading import Thread
|
| 9 |
|
| 10 |
# For getting tokenizer()
|
| 11 |
model_id = "meta-llama/Meta-Llama-3-8B-Instruct"
|
| 12 |
peft_model_adapter_id = "nttwt1597/test_v2_cancer_v3"
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 15 |
+
model_name = model_id,
|
| 16 |
max_seq_length = 4096,
|
| 17 |
dtype = None,
|
| 18 |
load_in_4bit = True,
|
|
|
|
| 24 |
tokenizer.convert_tokens_to_ids("<|eot_id|>")
|
| 25 |
]
|
| 26 |
|
| 27 |
+
FastLanguageModel.for_inference(model)
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
criteria_prompt = """Based on the provided instructions and clinical trial information, generate the eligibility criteria for the study.
|
| 30 |
|
|
|
|
| 56 |
yield generated_text
|
| 57 |
|
| 58 |
place_holder = f"""Study Objectives
|
| 59 |
+
The purpose of this study is to evaluate the safety, tolerance and efficacy of Liposomal Paclitaxel With Nedaplatin as First-line in patients with Advanced or Recurrent Esophageal Carcinoma
|
| 60 |
|
| 61 |
+
Conditions: Esophageal Carcinoma
|
| 62 |
|
| 63 |
+
Intervention / Treatment:
|
| 64 |
+
DRUG: Liposomal Paclitaxel,
|
| 65 |
+
DRUG: Nedaplatin
|
| 66 |
|
| 67 |
+
Location: China
|
|
|
|
|
|
|
| 68 |
|
| 69 |
+
Study Design and Phases
|
| 70 |
+
Study Type: INTERVENTIONAL
|
| 71 |
+
Phase: PHASE2 Primary Purpose:
|
| 72 |
+
TREATMENT Allocation: NA
|
| 73 |
+
Interventional Model: SINGLE_GROUP Masking: NONE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
"""
|
| 75 |
|
| 76 |
prefilled_value = """Study Objectives
|
| 77 |
[Brief Summary] and/or [Detailed Description]
|
| 78 |
|
| 79 |
+
Conditions: [Disease]
|
| 80 |
|
| 81 |
Intervention / Treatment
|
| 82 |
+
[DRUGs]
|
| 83 |
|
| 84 |
Location
|
| 85 |
+
[Location]
|
| 86 |
|
| 87 |
Study Design and Phases
|
| 88 |
+
Study Type:
|
| 89 |
+
Phase:
|
| 90 |
+
Primary Purpose:
|
| 91 |
+
Allocation:
|
| 92 |
+
Interventional Model:
|
| 93 |
+
Masking:"""
|
| 94 |
|
| 95 |
prompt_box = gr.Textbox(
|
| 96 |
lines=25,
|
|
|
|
| 111 |
allow_flagging='auto',
|
| 112 |
)
|
| 113 |
|
| 114 |
+
demo.queue(max_size=20).launch(debug=True, share=True)
|