Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,53 +16,22 @@ import numpy as np
|
|
| 16 |
import fitz
|
| 17 |
import pypdfium2 as pdfium
|
| 18 |
|
| 19 |
-
# Mouse callback function
|
| 20 |
def mouse_callback(event, x, y, flags, param):
|
| 21 |
if event == cv2.EVENT_LBUTTONDOWN:
|
| 22 |
-
|
| 23 |
elif event == cv2.EVENT_RBUTTONDOWN:
|
| 24 |
-
|
| 25 |
|
| 26 |
-
# Create a
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
iface
|
| 34 |
-
|
| 35 |
-
# Define the HTML template
|
| 36 |
-
html_template = '''
|
| 37 |
-
<!DOCTYPE html>
|
| 38 |
-
<html>
|
| 39 |
-
<body>
|
| 40 |
-
<h1>Enter Text</h1>
|
| 41 |
-
<form method="POST" action="/" enctype="multipart/form-data">
|
| 42 |
-
<input type="text" name="text">
|
| 43 |
-
<input type="submit" value="Submit">
|
| 44 |
-
</form>
|
| 45 |
-
<p>{{ mouse_event }}</p>
|
| 46 |
-
</body>
|
| 47 |
-
</html>
|
| 48 |
-
'''
|
| 49 |
-
|
| 50 |
-
# Set the route for the home page
|
| 51 |
-
@app.route('/', methods=['GET', 'POST'])
|
| 52 |
-
def home():
|
| 53 |
-
if request.method == 'POST':
|
| 54 |
-
# Get the user input text
|
| 55 |
-
input_text = request.form['text']
|
| 56 |
-
|
| 57 |
-
# Generate text using Hugging Face pipeline
|
| 58 |
-
generated_text = text_generator(input_text, max_length=50)[0]['generated_text']
|
| 59 |
-
|
| 60 |
-
# Render the template with the generated text and mouse event
|
| 61 |
-
return render_template_string(html_template, generated_text=generated_text, mouse_event=app.mouse_event)
|
| 62 |
-
|
| 63 |
-
# Render the template initially
|
| 64 |
-
return render_template_string(html_template)
|
| 65 |
-
|
| 66 |
-
# Launch the Flask app
|
| 67 |
-
if __name__ == '__main__':
|
| 68 |
-
app.run()
|
|
|
|
| 16 |
import fitz
|
| 17 |
import pypdfium2 as pdfium
|
| 18 |
|
|
|
|
| 19 |
def mouse_callback(event, x, y, flags, param):
|
| 20 |
if event == cv2.EVENT_LBUTTONDOWN:
|
| 21 |
+
print("Left button down at ({}, {})".format(x, y))
|
| 22 |
elif event == cv2.EVENT_RBUTTONDOWN:
|
| 23 |
+
print("Right button down at ({}, {})".format(x, y))
|
| 24 |
|
| 25 |
+
# Create a function to handle user input
|
| 26 |
+
def handle_image(image):
|
| 27 |
+
# Display the image
|
| 28 |
+
cv2.imshow("Image", image)
|
| 29 |
+
cv2.setMouseCallback("Image", mouse_callback)
|
| 30 |
+
cv2.waitKey(0)
|
| 31 |
+
cv2.destroyAllWindows()
|
| 32 |
|
| 33 |
+
# Define the Gradio interface without inputs
|
| 34 |
+
iface = gr.Interface(fn=handle_image, inputs=None, outputs="image")
|
| 35 |
|
| 36 |
+
# Launch the interface
|
| 37 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|