Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -106,13 +106,44 @@ def process_image(image, prompt):
|
|
106 |
response = ImageChat(image, prompt)
|
107 |
return response
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
app = gr.Interface(
|
110 |
fn=process_image,
|
111 |
inputs=[gr.Image(type="pil", label=""), gr.Textbox(label="Your Prompt", value="Analyze")],
|
112 |
-
outputs=[gr.HTML(label="Response")],
|
113 |
title="",
|
114 |
theme=gr.themes.Soft()
|
115 |
)
|
116 |
|
117 |
-
|
118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
response = ImageChat(image, prompt)
|
107 |
return response
|
108 |
|
109 |
+
# Custom JS for copy and export buttons
|
110 |
+
copy_js = """
|
111 |
+
async function copyOutput() {
|
112 |
+
const outputElement = document.getElementById('output');
|
113 |
+
const text = outputElement.innerText;
|
114 |
+
await navigator.clipboard.writeText(text);
|
115 |
+
alert('Copied to clipboard!');
|
116 |
+
}
|
117 |
+
"""
|
118 |
+
|
119 |
+
export_js = """
|
120 |
+
function exportOutput() {
|
121 |
+
const outputElement = document.getElementById('output');
|
122 |
+
const text = outputElement.innerText;
|
123 |
+
const blob = new Blob([text], { type: 'text/plain' });
|
124 |
+
const url = URL.createObjectURL(blob);
|
125 |
+
const a = document.createElement('a');
|
126 |
+
a.href = url;
|
127 |
+
a.download = 'output.txt';
|
128 |
+
document.body.appendChild(a);
|
129 |
+
a.click();
|
130 |
+
document.body.removeChild(a);
|
131 |
+
}
|
132 |
+
"""
|
133 |
+
|
134 |
app = gr.Interface(
|
135 |
fn=process_image,
|
136 |
inputs=[gr.Image(type="pil", label=""), gr.Textbox(label="Your Prompt", value="Analyze")],
|
137 |
+
outputs=[gr.HTML(label="Response", elem_id="output")],
|
138 |
title="",
|
139 |
theme=gr.themes.Soft()
|
140 |
)
|
141 |
|
142 |
+
app.launch(share=False, inline=True, server_name="0.0.0.0", server_port=7860)
|
143 |
+
|
144 |
+
# Include the buttons and custom JS in the launch method
|
145 |
+
with app:
|
146 |
+
gr.Button("Copy").click(None, None, None, _js=copy_js)
|
147 |
+
gr.Button("Export").click(None, None, None, _js=export_js)
|
148 |
+
|
149 |
+
app.launch()
|