Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1621,7 +1621,30 @@ def process_image_old_05152024(image_input):
|
|
| 1621 |
st.markdown(response.choices[0].message.content)
|
| 1622 |
|
| 1623 |
|
|
|
|
| 1624 |
def save_image(image_input, image_response):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1625 |
if image_input and image_response:
|
| 1626 |
# Extract emojis and first two words from each markdown line
|
| 1627 |
lines = image_response.split("\n")
|
|
|
|
| 1621 |
st.markdown(response.choices[0].message.content)
|
| 1622 |
|
| 1623 |
|
| 1624 |
+
|
| 1625 |
def save_image(image_input, image_response):
|
| 1626 |
+
if image_input and image_response:
|
| 1627 |
+
# Extract the first two alphanumeric words from each line
|
| 1628 |
+
lines = image_response.split("\n")
|
| 1629 |
+
filename_parts = []
|
| 1630 |
+
for line in lines:
|
| 1631 |
+
words = re.findall(r'\b\w+\b', line)
|
| 1632 |
+
alphanumeric_words = [word for word in words if word.isalnum()]
|
| 1633 |
+
if len(alphanumeric_words) >= 2:
|
| 1634 |
+
filename_parts.append(f"{alphanumeric_words[0]}_{alphanumeric_words[1]}")
|
| 1635 |
+
|
| 1636 |
+
# Create the filename by concatenating the extracted parts
|
| 1637 |
+
filename = "_".join(filename_parts)[:50] # Limit filename length to 50 characters
|
| 1638 |
+
filename = f"{filename}.png"
|
| 1639 |
+
|
| 1640 |
+
# Save the image with the new filename
|
| 1641 |
+
with open(filename, "wb") as f:
|
| 1642 |
+
f.write(image_input.getbuffer())
|
| 1643 |
+
|
| 1644 |
+
return filename
|
| 1645 |
+
|
| 1646 |
+
|
| 1647 |
+
def save_image_old(image_input, image_response):
|
| 1648 |
if image_input and image_response:
|
| 1649 |
# Extract emojis and first two words from each markdown line
|
| 1650 |
lines = image_response.split("\n")
|