awacke1 commited on
Commit
fb1f402
โ€ข
1 Parent(s): 73e1983

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -31
app.py CHANGED
@@ -1499,33 +1499,40 @@ def save_image(image_input, filename):
1499
 
1500
  def process_image(image_input):
1501
  if image_input:
1502
- base64_image = base64.b64encode(image_input.read()).decode("utf-8")
1503
- response = client.chat.completions.create(
1504
- model=MODEL,
1505
- messages=[
1506
- {"role": "system", "content": "You are a helpful assistant that responds in Markdown."},
1507
- {"role": "user", "content": [
1508
- {"type": "text", "text": "Help me understand what is in this picture and list ten facts as markdown outline with appropriate emojis that describes what you see."},
1509
- {"type": "image_url", "image_url": {
1510
- "url": f"data:image/png;base64,{base64_image}"}
1511
- }
1512
- ]}
1513
- ],
1514
- temperature=0.0,
1515
- )
1516
- image_response = response.choices[0].message.content
1517
- st.markdown(image_response)
1518
-
1519
- # Save markdown on image AI output from gpt4o
1520
- filename_md = f"{image_input.name}.md"
1521
- with open(filename_md, "w", encoding="utf-8") as f:
1522
- f.write(image_response)
1523
-
1524
- # Save copy of image with original filename
1525
- filename_img = image_input.name
1526
- save_image(image_input, filename_img)
1527
-
1528
- return image_response
 
 
 
 
 
 
 
1529
 
1530
  def save_imageold(image_input, filename_txt):
1531
  # Save the uploaded video file
@@ -1675,11 +1682,12 @@ def main():
1675
  text_input = st.text_input("Enter your text:")
1676
  if (text_input > ''):
1677
  textResponse = process_text(text_input)
1678
-
1679
  elif option == "Image":
1680
  image_input = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
1681
  image_response = process_image(image_input)
1682
- #st.markdown(image_response)
 
 
1683
  elif option == "Audio":
1684
  audio_input = st.file_uploader("Upload an audio file", type=["mp3", "wav"])
1685
  process_audio(audio_input)
@@ -1688,6 +1696,9 @@ def main():
1688
  process_audio_and_video(video_input)
1689
 
1690
  # Image and Video Galleries
 
 
 
1691
  num_columns_video=st.slider(key="num_columns_video", label="Choose Number of Video Columns", min_value=1, max_value=15, value=5)
1692
  display_videos_and_links(num_columns_video) # Video Jump Grid
1693
 
@@ -1699,8 +1710,6 @@ if showExtendedTextInterface:
1699
  num_columns_text=st.slider(key="num_columns_text", label="Choose Number of Text Columns", min_value=1, max_value=15, value=4)
1700
  display_buttons_with_scores(num_columns_text) # Feedback Jump Grid
1701
  st.markdown(personality_factors)
1702
- num_columns_images=st.slider(key="num_columns_images", label="Choose Number of Image Columns", min_value=1, max_value=15, value=5)
1703
- display_images_and_wikipedia_summaries(num_columns_images) # Image Jump Grid
1704
 
1705
 
1706
 
 
1499
 
1500
  def process_image(image_input):
1501
  if image_input:
1502
+ st.markdown('Processing image: ' + image_input.name )
1503
+ if image_input:
1504
+ base64_image = base64.b64encode(image_input.read()).decode("utf-8")
1505
+ response = client.chat.completions.create(
1506
+ model=MODEL,
1507
+ messages=[
1508
+ {"role": "system", "content": "You are a helpful assistant that responds in Markdown."},
1509
+ {"role": "user", "content": [
1510
+ {"type": "text", "text": "Help me understand what is in this picture and list ten facts as markdown outline with appropriate emojis that describes what you see."},
1511
+ {"type": "image_url", "image_url": {
1512
+ "url": f"data:image/png;base64,{base64_image}"}
1513
+ }
1514
+ ]}
1515
+ ],
1516
+ temperature=0.0,
1517
+ )
1518
+ image_response = response.choices[0].message.content
1519
+ st.markdown(image_response)
1520
+
1521
+ # Save markdown on image AI output from gpt4o
1522
+ filename_md = generate_filename(image_input.name + '- ' + image_response, "md")
1523
+ # Save markdown on image AI output from gpt4o
1524
+ filename_png = filename_md.replace('.md', '.' + image_input.name.split('.')[-1])
1525
+
1526
+ create_file(filename_md, image_response, '', True) #create_file() # create_file() 3 required positional arguments: 'filename', 'prompt', and 'response'
1527
+
1528
+ with open(filename_md, "w", encoding="utf-8") as f:
1529
+ f.write(image_response)
1530
+
1531
+ # Save copy of image with original filename
1532
+ filename_img = image_input.name
1533
+ save_image(image_input, filename_img)
1534
+
1535
+ return image_response
1536
 
1537
  def save_imageold(image_input, filename_txt):
1538
  # Save the uploaded video file
 
1682
  text_input = st.text_input("Enter your text:")
1683
  if (text_input > ''):
1684
  textResponse = process_text(text_input)
 
1685
  elif option == "Image":
1686
  image_input = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
1687
  image_response = process_image(image_input)
1688
+
1689
+
1690
+
1691
  elif option == "Audio":
1692
  audio_input = st.file_uploader("Upload an audio file", type=["mp3", "wav"])
1693
  process_audio(audio_input)
 
1696
  process_audio_and_video(video_input)
1697
 
1698
  # Image and Video Galleries
1699
+ num_columns_images=st.slider(key="num_columns_images", label="Choose Number of Image Columns", min_value=1, max_value=15, value=5)
1700
+ display_images_and_wikipedia_summaries(num_columns_images) # Image Jump Grid
1701
+
1702
  num_columns_video=st.slider(key="num_columns_video", label="Choose Number of Video Columns", min_value=1, max_value=15, value=5)
1703
  display_videos_and_links(num_columns_video) # Video Jump Grid
1704
 
 
1710
  num_columns_text=st.slider(key="num_columns_text", label="Choose Number of Text Columns", min_value=1, max_value=15, value=4)
1711
  display_buttons_with_scores(num_columns_text) # Feedback Jump Grid
1712
  st.markdown(personality_factors)
 
 
1713
 
1714
 
1715