Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -61,205 +61,99 @@ def run(history, text, image, audio_upload, audio_mic):
|
|
| 61 |
return history, None, None, None, None
|
| 62 |
|
| 63 |
|
| 64 |
-
#
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
# with gr.Blocks() as demo:
|
| 104 |
-
# gr.Markdown("## MultiModal Phi2 Model Pretraining and Finetuning from Scratch")
|
| 105 |
-
|
| 106 |
-
# with gr.Row():
|
| 107 |
-
# with gr.Column(scale=4):
|
| 108 |
-
# with gr.Box(style=interface_style["box"]):
|
| 109 |
-
# with gr.Row():
|
| 110 |
-
# prompt = gr.Textbox(
|
| 111 |
-
# placeholder="Enter Prompt",
|
| 112 |
-
# lines=2,
|
| 113 |
-
# label="Query",
|
| 114 |
-
# value=None,
|
| 115 |
-
# style=interface_style["textbox"],
|
| 116 |
-
# )
|
| 117 |
-
# with gr.Row():
|
| 118 |
-
# image = gr.Image(
|
| 119 |
-
# type="filepath", value=None, style=interface_style["image"]
|
| 120 |
-
# )
|
| 121 |
-
# with gr.Row():
|
| 122 |
-
# audio_upload = gr.Audio(
|
| 123 |
-
# source="upload", type="filepath", style=interface_style["audio"]
|
| 124 |
-
# )
|
| 125 |
-
# audio_mic = gr.Audio(
|
| 126 |
-
# source="microphone",
|
| 127 |
-
# type="filepath",
|
| 128 |
-
# format="mp3",
|
| 129 |
-
# style=interface_style["audio"],
|
| 130 |
-
# )
|
| 131 |
-
|
| 132 |
-
# with gr.Column(scale=8):
|
| 133 |
-
# with gr.Box(style=interface_style["box"]):
|
| 134 |
-
# with gr.Row():
|
| 135 |
-
# chatbot = gr.Chatbot(
|
| 136 |
-
# avatar_images=("🧑", "🤖"),
|
| 137 |
-
# height=550,
|
| 138 |
-
# style=interface_style["chatbox"],
|
| 139 |
-
# )
|
| 140 |
-
# with gr.Row():
|
| 141 |
-
# submit = gr.Button(style=interface_style["button"])
|
| 142 |
-
# clear = gr.Button(value="Clear", style=interface_style["button"])
|
| 143 |
-
|
| 144 |
-
# submit.click(
|
| 145 |
-
# add_content,
|
| 146 |
-
# inputs=[chatbot, prompt, image, audio_upload, audio_mic],
|
| 147 |
-
# outputs=[chatbot],
|
| 148 |
-
# ).success(
|
| 149 |
-
# run,
|
| 150 |
-
# inputs=[chatbot, prompt, image, audio_upload, audio_mic],
|
| 151 |
-
# outputs=[chatbot, prompt, image, audio_upload, audio_mic],
|
| 152 |
-
# )
|
| 153 |
-
|
| 154 |
-
# clear.click(
|
| 155 |
-
# clear_data,
|
| 156 |
-
# outputs=[prompt, image, audio_upload, audio_mic, chatbot],
|
| 157 |
-
# )
|
| 158 |
-
|
| 159 |
-
# demo.launch()
|
| 160 |
-
|
| 161 |
-
custom_html = """
|
| 162 |
-
<!DOCTYPE html>
|
| 163 |
-
<html lang="en">
|
| 164 |
-
<head>
|
| 165 |
-
<meta charset="UTF-8">
|
| 166 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 167 |
-
<style>
|
| 168 |
-
body {
|
| 169 |
-
font-family: 'Arial', sans-serif;
|
| 170 |
-
background-color: #f4f4f4;
|
| 171 |
-
margin: 0;
|
| 172 |
-
padding: 0;
|
| 173 |
-
}
|
| 174 |
-
#container {
|
| 175 |
-
max-width: 800px;
|
| 176 |
-
margin: 20px auto;
|
| 177 |
-
padding: 20px;
|
| 178 |
-
background-color: #fff;
|
| 179 |
-
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
| 180 |
-
border-radius: 10px;
|
| 181 |
-
display: flex;
|
| 182 |
-
flex-direction: column;
|
| 183 |
-
align-items: center;
|
| 184 |
-
}
|
| 185 |
-
label {
|
| 186 |
-
font-weight: bold;
|
| 187 |
-
margin-bottom: 5px;
|
| 188 |
-
display: block;
|
| 189 |
-
}
|
| 190 |
-
textarea, input[type="file"] {
|
| 191 |
-
width: 100%;
|
| 192 |
-
padding: 10px;
|
| 193 |
-
margin-bottom: 10px;
|
| 194 |
-
box-sizing: border-box;
|
| 195 |
-
}
|
| 196 |
-
button {
|
| 197 |
-
background-color: #4caf50;
|
| 198 |
-
color: #fff;
|
| 199 |
-
padding: 10px;
|
| 200 |
-
border: none;
|
| 201 |
-
border-radius: 5px;
|
| 202 |
-
cursor: pointer;
|
| 203 |
-
}
|
| 204 |
-
button:hover {
|
| 205 |
-
background-color: #45a049;
|
| 206 |
-
}
|
| 207 |
-
#chat-container {
|
| 208 |
-
max-height: 550px;
|
| 209 |
-
overflow-y: auto;
|
| 210 |
-
border: 1px solid #ddd;
|
| 211 |
-
padding: 10px;
|
| 212 |
-
border-radius: 5px;
|
| 213 |
-
background-color: #f0f0f0;
|
| 214 |
-
margin-top: 10px;
|
| 215 |
-
}
|
| 216 |
-
</style>
|
| 217 |
-
</head>
|
| 218 |
-
<body>
|
| 219 |
-
<div id="container">
|
| 220 |
-
<h2 style="text-align: center;">MultiModal Phi2 Model Pretraining and Finetuning from Scratch</h2>
|
| 221 |
-
<div style="display: flex; width: 100%;">
|
| 222 |
-
<div style="flex: 1; margin-right: 10px;">
|
| 223 |
-
<label for="inputText">Text Input:</label>
|
| 224 |
-
<textarea id="inputText" name="inputText" placeholder="Enter Prompt" rows="4"></textarea>
|
| 225 |
-
|
| 226 |
-
<label for="inputImage">Image Input:</label>
|
| 227 |
-
<input type="file" id="inputImage" name="inputImage" accept="image/*">
|
| 228 |
-
|
| 229 |
-
<label for="inputAudio">Audio Input:</label>
|
| 230 |
-
<input type="file" id="inputAudio" name="inputAudio" accept="audio/*">
|
| 231 |
-
</div>
|
| 232 |
-
<div style="flex: 2;">
|
| 233 |
-
<div id="chat-container"></div>
|
| 234 |
-
</div>
|
| 235 |
-
</div>
|
| 236 |
-
<button id="submitBtn">Submit</button>
|
| 237 |
-
<button id="clearBtn" style="background-color: #f44336;">Clear</button>
|
| 238 |
-
</div>
|
| 239 |
-
|
| 240 |
-
<script>
|
| 241 |
-
document.getElementById('submitBtn').addEventListener('click', function() {
|
| 242 |
-
// Add your logic to process and update the chat
|
| 243 |
-
// Example: Update the chat with a placeholder response
|
| 244 |
-
var inputText = document.getElementById('inputText').value;
|
| 245 |
-
var chatContainer = document.getElementById('chat-container');
|
| 246 |
-
var response = "<strong>User:</strong> " + inputText + "<br><strong>Model:</strong> This is a placeholder response.<br>";
|
| 247 |
-
chatContainer.innerHTML += response;
|
| 248 |
-
});
|
| 249 |
-
|
| 250 |
-
document.getElementById('clearBtn').addEventListener('click', function() {
|
| 251 |
-
// Clear input and chat
|
| 252 |
-
document.getElementById('inputText').value = '';
|
| 253 |
-
document.getElementById('inputImage').value = '';
|
| 254 |
-
document.getElementById('inputAudio').value = '';
|
| 255 |
-
document.getElementById('chat-container').innerHTML = '';
|
| 256 |
-
});
|
| 257 |
-
</script>
|
| 258 |
-
</body>
|
| 259 |
-
</html>
|
| 260 |
-
"""
|
| 261 |
|
| 262 |
with gr.Blocks() as demo:
|
| 263 |
-
gr.
|
| 264 |
-
|
| 265 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
return history, None, None, None, None
|
| 62 |
|
| 63 |
|
| 64 |
+
# Custom styling
|
| 65 |
+
interface_style = {
|
| 66 |
+
"box": {
|
| 67 |
+
"backgroundColor": "#f9f9f9",
|
| 68 |
+
"padding": "20px",
|
| 69 |
+
"borderRadius": "10px",
|
| 70 |
+
"boxShadow": "0 0 10px rgba(0, 0, 0, 0.1)",
|
| 71 |
+
},
|
| 72 |
+
"button": {
|
| 73 |
+
"backgroundColor": "#4caf50",
|
| 74 |
+
"color": "#fff",
|
| 75 |
+
"padding": "10px",
|
| 76 |
+
"border": "none",
|
| 77 |
+
"borderRadius": "5px",
|
| 78 |
+
"cursor": "pointer",
|
| 79 |
+
},
|
| 80 |
+
"textbox": {
|
| 81 |
+
"width": "100%",
|
| 82 |
+
"padding": "10px",
|
| 83 |
+
"marginBottom": "10px",
|
| 84 |
+
"boxSizing": "border-box",
|
| 85 |
+
},
|
| 86 |
+
"image": {
|
| 87 |
+
"width": "100%",
|
| 88 |
+
"marginBottom": "10px",
|
| 89 |
+
},
|
| 90 |
+
"audio": {
|
| 91 |
+
"width": "100%",
|
| 92 |
+
"marginBottom": "10px",
|
| 93 |
+
},
|
| 94 |
+
"chatbox": {
|
| 95 |
+
"height": "550px",
|
| 96 |
+
"backgroundColor": "#f0f0f0",
|
| 97 |
+
"borderRadius": "5px",
|
| 98 |
+
"padding": "10px",
|
| 99 |
+
"overflowY": "auto",
|
| 100 |
+
},
|
| 101 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
with gr.Blocks() as demo:
|
| 104 |
+
gr.Markdown("## MultiModal Phi2 Model Pretraining and Finetuning from Scratch")
|
| 105 |
+
|
| 106 |
+
with gr.Row():
|
| 107 |
+
with gr.Column(scale=4):
|
| 108 |
+
with gr.Box(style=interface_style["box"]):
|
| 109 |
+
with gr.Row():
|
| 110 |
+
prompt = gr.Textbox(
|
| 111 |
+
placeholder="Enter Prompt",
|
| 112 |
+
lines=2,
|
| 113 |
+
label="Query",
|
| 114 |
+
value=None,
|
| 115 |
+
style=interface_style["textbox"],
|
| 116 |
+
)
|
| 117 |
+
with gr.Row():
|
| 118 |
+
image = gr.Image(
|
| 119 |
+
type="filepath", value=None, style=interface_style["image"]
|
| 120 |
+
)
|
| 121 |
+
with gr.Row():
|
| 122 |
+
audio_upload = gr.Audio(
|
| 123 |
+
source="upload", type="filepath", style=interface_style["audio"]
|
| 124 |
+
)
|
| 125 |
+
audio_mic = gr.Audio(
|
| 126 |
+
source="microphone",
|
| 127 |
+
type="filepath",
|
| 128 |
+
format="mp3",
|
| 129 |
+
style=interface_style["audio"],
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
with gr.Column(scale=8):
|
| 133 |
+
with gr.Box(style=interface_style["box"]):
|
| 134 |
+
with gr.Row():
|
| 135 |
+
chatbot = gr.Chatbot(
|
| 136 |
+
avatar_images=("🧑", "🤖"),
|
| 137 |
+
height=550,
|
| 138 |
+
style=interface_style["chatbox"],
|
| 139 |
+
)
|
| 140 |
+
with gr.Row():
|
| 141 |
+
submit = gr.Button(style=interface_style["button"])
|
| 142 |
+
clear = gr.Button(value="Clear", style=interface_style["button"])
|
| 143 |
+
|
| 144 |
+
submit.click(
|
| 145 |
+
add_content,
|
| 146 |
+
inputs=[chatbot, prompt, image, audio_upload, audio_mic],
|
| 147 |
+
outputs=[chatbot],
|
| 148 |
+
).success(
|
| 149 |
+
run,
|
| 150 |
+
inputs=[chatbot, prompt, image, audio_upload, audio_mic],
|
| 151 |
+
outputs=[chatbot, prompt, image, audio_upload, audio_mic],
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
clear.click(
|
| 155 |
+
clear_data,
|
| 156 |
+
outputs=[prompt, image, audio_upload, audio_mic, chatbot],
|
| 157 |
+
)
|
| 158 |
+
|
| 159 |
+
demo.launch()
|