Spaces:
Runtime error
Runtime error
heecheol.park commited on
Commit Β·
737d609
1
Parent(s): a3b945a
revert: remove copy to clipboard feature and return to original code
Browse files
app.py
CHANGED
|
@@ -9,42 +9,11 @@ def ocr_image_to_text(image: Image.Image):
|
|
| 9 |
text = pytesseract.image_to_string(image_cv, lang='eng+kor')
|
| 10 |
return text
|
| 11 |
|
| 12 |
-
|
| 13 |
-
COPY_TO_CLIPBOARD_SCRIPT = """
|
| 14 |
-
<script>
|
| 15 |
-
function copyToClipboard() {
|
| 16 |
-
const textArea = document.createElement('textarea');
|
| 17 |
-
textArea.value = document.getElementById('output-text').innerText;
|
| 18 |
-
document.body.appendChild(textArea);
|
| 19 |
-
textArea.select();
|
| 20 |
-
document.execCommand('copy');
|
| 21 |
-
document.body.removeChild(textArea);
|
| 22 |
-
}
|
| 23 |
-
</script>
|
| 24 |
-
"""
|
| 25 |
-
|
| 26 |
-
template = gr.templates.Template(
|
| 27 |
-
input_template=gr.templates.custom_templates.INPUT_TEMPLATE,
|
| 28 |
-
output_template=f"""
|
| 29 |
-
<style>
|
| 30 |
-
#output-text {{
|
| 31 |
-
white-space: pre-wrap;
|
| 32 |
-
}}
|
| 33 |
-
</style>
|
| 34 |
-
<div id="output-text">{{{output}}}</div>
|
| 35 |
-
<button onclick="copyToClipboard()">Copy to Clipboard</button>
|
| 36 |
-
{COPY_TO_CLIPBOARD_SCRIPT}
|
| 37 |
-
""",
|
| 38 |
-
input_width=6,
|
| 39 |
-
output_width=6,
|
| 40 |
-
)
|
| 41 |
-
|
| 42 |
-
|
| 43 |
# Gradio μΈν°νμ΄μ€λ₯Ό μ μν©λλ€.
|
| 44 |
image_input = gr.inputs.Image(label="Upload an image")
|
| 45 |
text_output = gr.outputs.Textbox(label="Extracted Text")
|
| 46 |
|
| 47 |
-
iface = gr.Interface(fn=ocr_image_to_text, inputs=image_input, outputs=text_output, title="OCR Image to Text"
|
| 48 |
|
| 49 |
# μΈν°νμ΄μ€λ₯Ό μ€ννκ³ Hugging Face Spacesμ λ°°ν¬ν©λλ€.
|
| 50 |
iface.launch()
|
|
|
|
| 9 |
text = pytesseract.image_to_string(image_cv, lang='eng+kor')
|
| 10 |
return text
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
# Gradio μΈν°νμ΄μ€λ₯Ό μ μν©λλ€.
|
| 13 |
image_input = gr.inputs.Image(label="Upload an image")
|
| 14 |
text_output = gr.outputs.Textbox(label="Extracted Text")
|
| 15 |
|
| 16 |
+
iface = gr.Interface(fn=ocr_image_to_text, inputs=image_input, outputs=text_output, title="OCR Image to Text")
|
| 17 |
|
| 18 |
# μΈν°νμ΄μ€λ₯Ό μ€ννκ³ Hugging Face Spacesμ λ°°ν¬ν©λλ€.
|
| 19 |
iface.launch()
|