Adapters
English
code
medical
dnnsdunca commited on
Commit
6fe47f5
1 Parent(s): da08aaf

Create App.py

Browse files
Files changed (1) hide show
  1. App.py +48 -0
App.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ from transformers import BertTokenizer, TFBertModel
4
+ import numpy as np
5
+
6
+ # Load your model
7
+ model = tf.keras.models.load_model('models/model_files')
8
+
9
+ # Load tokenizer
10
+ tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
11
+
12
+ def preprocess_text(text):
13
+ inputs = tokenizer(text, return_tensors='tf', padding=True, truncation=True, max_length=512)
14
+ return inputs
15
+
16
+ def predict(text, image, structured):
17
+ text_inputs = preprocess_text(text)
18
+ image = tf.image.resize(image, (224, 224))
19
+ image = tf.keras.applications.resnet50.preprocess_input(image)
20
+ structured = (structured - structured.mean()) / structured.std()
21
+ prediction = model.predict([text_inputs['input_ids'], text_inputs['attention_mask'], image, structured])
22
+ return prediction[0][0]
23
+
24
+ # Define the chat function
25
+ def chat_response(user_input):
26
+ return f"Model response to: {user_input}"
27
+
28
+ # Define the code execution function
29
+ def execute_code(code):
30
+ exec_globals = {}
31
+ exec(code, exec_globals)
32
+ return exec_globals.get("output", "No output")
33
+
34
+ with gr.Blocks() as demo:
35
+ with gr.Row():
36
+ with gr.Column():
37
+ chat_input = gr.Textbox(lines=2, placeholder="Enter your message here...")
38
+ chat_output = gr.Textbox(lines=5, placeholder="Model response will appear here...")
39
+ chat_button = gr.Button("Send")
40
+ with gr.Column():
41
+ code_input = gr.Textbox(lines=10, placeholder="Enter your code here...")
42
+ code_output = gr.Textbox(lines=5, placeholder="Code output will appear here...")
43
+ code_button = gr.Button("Run Code")
44
+
45
+ chat_button.click(chat_response, inputs=chat_input, outputs=chat_output)
46
+ code_button.click(execute_code, inputs=code_input, outputs=code_output)
47
+
48
+ demo.launch()