Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1620,38 +1620,12 @@ def process_image_old_05152024(image_input):
|
|
1620 |
)
|
1621 |
st.markdown(response.choices[0].message.content)
|
1622 |
|
1623 |
-
def save_image(image_input):
|
1624 |
# Save the uploaded video file
|
1625 |
-
with open(
|
1626 |
f.write(image_input.getbuffer())
|
1627 |
return image_input.name
|
1628 |
|
1629 |
-
def save_image(image_input, image_response):
|
1630 |
-
if image_input is not None:
|
1631 |
-
# Save the uploaded video file
|
1632 |
-
image_path = save_image(image_input)
|
1633 |
-
return image_path # finish below code where it infers file naming from response
|
1634 |
-
|
1635 |
-
if image_input and image_response:
|
1636 |
-
# Extract the first two alphanumeric words from each line
|
1637 |
-
lines = image_response.split("\n")
|
1638 |
-
filename_parts = []
|
1639 |
-
for line in lines:
|
1640 |
-
words = re.findall(r'\b\w+\b', line)
|
1641 |
-
alphanumeric_words = [word for word in words if word.isalnum()]
|
1642 |
-
if len(alphanumeric_words) >= 2:
|
1643 |
-
filename_parts.append(f"{alphanumeric_words[0]}_{alphanumeric_words[1]}")
|
1644 |
-
|
1645 |
-
# Create the filename by concatenating the extracted parts
|
1646 |
-
filename = "_".join(filename_parts)[:50] # Limit filename length to 50 characters
|
1647 |
-
filename = f"{filename}.png"
|
1648 |
-
|
1649 |
-
# Save the image with the new filename
|
1650 |
-
with open(filename, "wb") as f:
|
1651 |
-
f.write(image_input.getbuffer())
|
1652 |
-
|
1653 |
-
return filename
|
1654 |
-
|
1655 |
def process_image(image_input):
|
1656 |
if image_input:
|
1657 |
base64_image = base64.b64encode(image_input.read()).decode("utf-8")
|
@@ -1670,10 +1644,16 @@ def process_image(image_input):
|
|
1670 |
)
|
1671 |
image_response = response.choices[0].message.content
|
1672 |
st.markdown(image_response)
|
|
|
1673 |
|
1674 |
# Save the image with a new filename based on the response
|
1675 |
-
#save_image(image_input, image_response)
|
1676 |
-
|
|
|
|
|
|
|
|
|
|
|
1677 |
|
1678 |
def process_audio(audio_input):
|
1679 |
if audio_input:
|
|
|
1620 |
)
|
1621 |
st.markdown(response.choices[0].message.content)
|
1622 |
|
1623 |
+
def save_image(image_input, filename_txt):
|
1624 |
# Save the uploaded video file
|
1625 |
+
with open(filename_txt, "wb") as f:
|
1626 |
f.write(image_input.getbuffer())
|
1627 |
return image_input.name
|
1628 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1629 |
def process_image(image_input):
|
1630 |
if image_input:
|
1631 |
base64_image = base64.b64encode(image_input.read()).decode("utf-8")
|
|
|
1644 |
)
|
1645 |
image_response = response.choices[0].message.content
|
1646 |
st.markdown(image_response)
|
1647 |
+
create_file()
|
1648 |
|
1649 |
# Save the image with a new filename based on the response
|
1650 |
+
#save_image(image_input, image_response)
|
1651 |
+
|
1652 |
+
filename_txt = generate_filename(image_response, "md")
|
1653 |
+
create_file(filename_txt, transcript, response, should_save)
|
1654 |
+
|
1655 |
+
filename_txt = generate_filename(image_response, "png")
|
1656 |
+
save_image(image_input, filename_txt)
|
1657 |
|
1658 |
def process_audio(audio_input):
|
1659 |
if audio_input:
|