Bump to v1.0.9: Fix counter bug, use emoji shortcodes, and add loading spinner UI.
This commit is contained in:
parent
ce2a9a03de
commit
b7ae9a6484
19
app.py
19
app.py
|
|
@ -11,11 +11,7 @@ app = Flask(__name__)
|
||||||
app.secret_key = os.environ.get("FLASK_SECRET_KEY", "prod-secret-7721")
|
app.secret_key = os.environ.get("FLASK_SECRET_KEY", "prod-secret-7721")
|
||||||
|
|
||||||
metrics = PrometheusMetrics(app)
|
metrics = PrometheusMetrics(app)
|
||||||
metrics.info('app_info', 'Application info', version='1.0.8')
|
metrics.info('app_info', 'Application info', version='1.0.9')
|
||||||
|
|
||||||
conversion_counter = metrics.counter(
|
|
||||||
'txt2md_conversions_total', 'Total number of text conversions'
|
|
||||||
)
|
|
||||||
|
|
||||||
# API Configuration
|
# API Configuration
|
||||||
api_key = os.environ.get("AI_API_KEY")
|
api_key = os.environ.get("AI_API_KEY")
|
||||||
|
|
@ -25,8 +21,9 @@ if api_key:
|
||||||
"You are a text-to-markdown conversion specialist. You always produce "
|
"You are a text-to-markdown conversion specialist. You always produce "
|
||||||
"standard CommonMark/GitHub Flavored Markdown. You strictly use ATX "
|
"standard CommonMark/GitHub Flavored Markdown. You strictly use ATX "
|
||||||
"headings (#) and never use wiki-style syntax like '==' or '==='. "
|
"headings (#) and never use wiki-style syntax like '==' or '==='. "
|
||||||
"Additionally, you insert relevant and tasteful emojis at the beginning "
|
"Additionally, you insert relevant and tasteful emojis as Markdown "
|
||||||
"of section headings to represent the topic."
|
"shortcodes (e.g., :rocket:, :bulb:, :memo:) at the beginning of section "
|
||||||
|
"headings to represent the topic."
|
||||||
)
|
)
|
||||||
model = genai.GenerativeModel(
|
model = genai.GenerativeModel(
|
||||||
model_name='gemini-2.5-flash',
|
model_name='gemini-2.5-flash',
|
||||||
|
|
@ -36,6 +33,8 @@ else:
|
||||||
model = None
|
model = None
|
||||||
|
|
||||||
@app.route("/", methods=["GET", "POST"])
|
@app.route("/", methods=["GET", "POST"])
|
||||||
|
@metrics.counter('txt2md_conversions_total', 'Total number of text conversions',
|
||||||
|
labels={'result': lambda: request.method})
|
||||||
def index():
|
def index():
|
||||||
converted_html = None
|
converted_html = None
|
||||||
markdown_content = ""
|
markdown_content = ""
|
||||||
|
|
@ -54,13 +53,13 @@ def index():
|
||||||
prompt = (
|
prompt = (
|
||||||
f"Convert the following text into high-quality standard Markdown. "
|
f"Convert the following text into high-quality standard Markdown. "
|
||||||
f"Use ATX headings (#), standard formatting, and include relevant "
|
f"Use ATX headings (#), standard formatting, and include relevant "
|
||||||
f"emojis for each section heading to make the document more engaging. "
|
f"emoji shortcodes (like :smile:) for each section heading to make "
|
||||||
f"Return ONLY the markdown content:\n\n{original_text}"
|
f"the document more engaging. Return ONLY the markdown content:\n\n"
|
||||||
|
f"{original_text}"
|
||||||
)
|
)
|
||||||
response = model.generate_content(prompt)
|
response = model.generate_content(prompt)
|
||||||
markdown_content = response.text
|
markdown_content = response.text
|
||||||
converted_html = markdown(markdown_content, extensions=['extra', 'codehilite'])
|
converted_html = markdown(markdown_content, extensions=['extra', 'codehilite'])
|
||||||
conversion_counter.inc()
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
flash(f"Error during processing: {str(e)}", "error")
|
flash(f"Error during processing: {str(e)}", "error")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ spec:
|
||||||
serviceAccountName: txt2md-sa
|
serviceAccountName: txt2md-sa
|
||||||
containers:
|
containers:
|
||||||
- name: txt2md
|
- name: txt2md
|
||||||
image: europe-west3-docker.pkg.dev/project-84ddd43d-e408-4cb9-8cb/txt2md-repo/txt2md:v1.0.8
|
image: europe-west3-docker.pkg.dev/project-84ddd43d-e408-4cb9-8cb/txt2md-repo/txt2md:v1.0.9
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 5000
|
- containerPort: 5000
|
||||||
env:
|
env:
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,9 @@ textarea:focus {
|
||||||
}
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
display: block;
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 0.75rem;
|
padding: 0.75rem;
|
||||||
margin-top: 1rem;
|
margin-top: 1rem;
|
||||||
|
|
@ -84,13 +86,38 @@ button {
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: background-color 0.3s ease;
|
transition: all 0.3s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
button:hover {
|
button:hover:not(:disabled) {
|
||||||
background-color: #2980b9;
|
background-color: #2980b9;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
button:disabled {
|
||||||
|
background-color: #a5ccea;
|
||||||
|
cursor: not-allowed;
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spinner {
|
||||||
|
display: none;
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
border: 3px solid rgba(255, 255, 255, 0.3);
|
||||||
|
border-radius: 50%;
|
||||||
|
border-top-color: #fff;
|
||||||
|
animation: spin 1s ease-in-out infinite;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
to { transform: rotate(360deg); }
|
||||||
|
}
|
||||||
|
|
||||||
|
button.loading .spinner {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
.preview {
|
.preview {
|
||||||
background-color: white;
|
background-color: white;
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,12 @@
|
||||||
<div class="editor-grid">
|
<div class="editor-grid">
|
||||||
<section class="input-section">
|
<section class="input-section">
|
||||||
<h2>Raw Input</h2>
|
<h2>Raw Input</h2>
|
||||||
<form method="POST">
|
<form id="convert-form" method="POST">
|
||||||
<textarea name="text" placeholder="Paste your text here..." required>{{ original_text }}</textarea>
|
<textarea name="text" placeholder="Paste your text here..." required>{{ original_text }}</textarea>
|
||||||
<button type="submit">Convert</button>
|
<button type="submit" id="convert-btn">
|
||||||
|
<span class="spinner"></span>
|
||||||
|
<span class="btn-text">Convert</span>
|
||||||
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
@ -47,5 +50,14 @@
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.getElementById('convert-form').addEventListener('submit', function() {
|
||||||
|
const btn = document.getElementById('convert-btn');
|
||||||
|
btn.disabled = true;
|
||||||
|
btn.classList.add('loading');
|
||||||
|
btn.querySelector('.btn-text').textContent = 'Converting...';
|
||||||
|
});
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue