Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,17 +27,20 @@ def mouse_callback(event, x, y, flags, param):
|
|
| 27 |
# Create a Flask app
|
| 28 |
app = Flask(__name__)
|
| 29 |
|
|
|
|
|
|
|
|
|
|
| 30 |
# Define the Gradio interface
|
| 31 |
-
iface = gr.Interface(fn=
|
| 32 |
|
| 33 |
# Define the HTML template
|
| 34 |
html_template = '''
|
| 35 |
<!DOCTYPE html>
|
| 36 |
<html>
|
| 37 |
<body>
|
| 38 |
-
<h1>
|
| 39 |
<form method="POST" action="/" enctype="multipart/form-data">
|
| 40 |
-
<input type="
|
| 41 |
<input type="submit" value="Submit">
|
| 42 |
</form>
|
| 43 |
<p>{{ mouse_event }}</p>
|
|
@@ -49,17 +52,14 @@ html_template = '''
|
|
| 49 |
@app.route('/', methods=['GET', 'POST'])
|
| 50 |
def home():
|
| 51 |
if request.method == 'POST':
|
| 52 |
-
# Get the
|
| 53 |
-
|
| 54 |
|
| 55 |
-
#
|
| 56 |
-
|
| 57 |
-
cv2.setMouseCallback("Image", mouse_callback)
|
| 58 |
-
cv2.waitKey(0)
|
| 59 |
-
cv2.destroyAllWindows()
|
| 60 |
|
| 61 |
-
# Render the template with the mouse event
|
| 62 |
-
return render_template_string(html_template, mouse_event=app.mouse_event)
|
| 63 |
|
| 64 |
# Render the template initially
|
| 65 |
return render_template_string(html_template)
|
|
|
|
| 27 |
# Create a Flask app
|
| 28 |
app = Flask(__name__)
|
| 29 |
|
| 30 |
+
# Load the Hugging Face pipeline for text generation
|
| 31 |
+
text_generator = pipeline("text-generation", model="gpt2")
|
| 32 |
+
|
| 33 |
# Define the Gradio interface
|
| 34 |
+
iface = gr.Interface(fn=text_generator, inputs="text", outputs="text")
|
| 35 |
|
| 36 |
# Define the HTML template
|
| 37 |
html_template = '''
|
| 38 |
<!DOCTYPE html>
|
| 39 |
<html>
|
| 40 |
<body>
|
| 41 |
+
<h1>Enter Text</h1>
|
| 42 |
<form method="POST" action="/" enctype="multipart/form-data">
|
| 43 |
+
<input type="text" name="text">
|
| 44 |
<input type="submit" value="Submit">
|
| 45 |
</form>
|
| 46 |
<p>{{ mouse_event }}</p>
|
|
|
|
| 52 |
@app.route('/', methods=['GET', 'POST'])
|
| 53 |
def home():
|
| 54 |
if request.method == 'POST':
|
| 55 |
+
# Get the user input text
|
| 56 |
+
input_text = request.form['text']
|
| 57 |
|
| 58 |
+
# Generate text using Hugging Face pipeline
|
| 59 |
+
generated_text = text_generator(input_text, max_length=50)[0]['generated_text']
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
+
# Render the template with the generated text and mouse event
|
| 62 |
+
return render_template_string(html_template, generated_text=generated_text, mouse_event=app.mouse_event)
|
| 63 |
|
| 64 |
# Render the template initially
|
| 65 |
return render_template_string(html_template)
|