BINAII commited on
Commit
920c612
·
verified ·
1 Parent(s): f7094c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -62
app.py CHANGED
@@ -1,64 +1,9 @@
1
- import gradio as gr
2
- from huggingface_hub import InferenceClient
3
 
4
- # Load the ClinicalBERT model
5
- MODEL_NAME = "emilyalsentzer/Bio_ClinicalBERT"
6
- client = InferenceClient(MODEL_NAME)
 
7
 
8
- def respond(
9
- message,
10
- history,
11
- system_message,
12
- max_tokens,
13
- temperature,
14
- top_p,
15
- ):
16
- if history is None:
17
- history = []
18
-
19
- messages = [{"role": "system", "content": system_message}]
20
-
21
- for val in history:
22
- if val[0]:
23
- messages.append({"role": "user", "content": val[0]})
24
- if val[1]:
25
- messages.append({"role": "assistant", "content": val[1]})
26
-
27
- messages.append({"role": "user", "content": message})
28
-
29
- # Ensure input includes [MASK] for ClinicalBERT
30
- if "[MASK]" not in message:
31
- message += " [MASK]"
32
-
33
- try:
34
- response = client.fill_mask(message)
35
- prediction = response[0]["sequence"]
36
- confidence = response[0]["score"]
37
-
38
- # Append to history
39
- history.append((message, prediction))
40
-
41
- return prediction, history # Must return history explicitly as an output
42
-
43
- except Exception as e:
44
- return {"error": str(e)}, history
45
-
46
- # Create Gradio interface
47
- demo = gr.Interface(
48
- fn=respond,
49
- inputs=[
50
- gr.Textbox(label="User Input"),
51
- gr.State(), # Explicit state for history tracking
52
- gr.Textbox(value="You are a friendly medical assistant.", label="System message"),
53
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
54
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
55
- gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p"),
56
- ],
57
- outputs=[
58
- gr.Textbox(label="Model Response"),
59
- gr.State(), # Explicit state output
60
- ],
61
- )
62
-
63
- if __name__ == "__main__":
64
- demo.launch(share=True)
 
1
+ import json
 
2
 
3
+ # Load the dataset (update 'your_file_path.json' with the actual file location)
4
+ file_path = "/Users/atibaraymond/Downloads/22687585/release_conditions.json"
5
+ with open(file_path, "r") as file:
6
+ data = json.load(file)
7
 
8
+ # Display a sample record
9
+ print(data[0]) # Print the first patient record