Juho Inkinen commited on
Commit
1ccaee5
·
unverified ·
1 Parent(s): 0d72f03

Remove redundant code; move all imports to top of module

Browse files
Files changed (1) hide show
  1. app.py +2 -16
app.py CHANGED
@@ -2,6 +2,8 @@ import gradio as gr
2
  import requests
3
  from annif_client import AnnifClient
4
  import os
 
 
5
 
6
 
7
  # Get VLM API base URL and API key from environment variables
@@ -24,8 +26,6 @@ else:
24
 
25
  def get_caption(image, prompt):
26
  # Convert image to base64 JPEG
27
- import io
28
- import base64
29
 
30
  buf = io.BytesIO()
31
  image.save(buf, format="JPEG")
@@ -74,20 +74,6 @@ def get_subjects(caption, project_id):
74
  raise gr.Error("Sorry, there was a problem getting subject suggestions.")
75
 
76
 
77
- def process_image(image, project_id):
78
- prompt = (
79
- "Luo vaihtoehtoinen tekstikuvaus, joka on tarkoitettu henkilöille, jotka eivät näe kuvaa. "
80
- "Kuvaile kuvan todellista sisältöä, älä tulkitse mitään. "
81
- "Aloita yleisellä kuvauksella ja siirry sitten yksityiskohtiin. "
82
- "Kuvaile yksityiskohtia ainakin viiden lauseen verran. "
83
- "Jos kuvassa näkyy tekstiä, kerro mitä siinä lukee ja jos teksti ei ole suomea, käännä se myös suomeksi. "
84
- 'Vastaa vain lopullisella alt-tekstillä, älä lisää "tässä on alt-teksti", selityksiä tai väliotsikoita. '
85
- )
86
- caption = get_caption(image, prompt)
87
- subjects = get_subjects(caption, project_id)
88
- return image, caption, subjects
89
-
90
-
91
  with gr.Blocks(title="VLM Caption & Annif Demo") as demo:
92
  gr.Markdown("# VLM Caption & Annif Demo")
93
  gr.Markdown(
 
2
  import requests
3
  from annif_client import AnnifClient
4
  import os
5
+ import io
6
+ import base64
7
 
8
 
9
  # Get VLM API base URL and API key from environment variables
 
26
 
27
  def get_caption(image, prompt):
28
  # Convert image to base64 JPEG
 
 
29
 
30
  buf = io.BytesIO()
31
  image.save(buf, format="JPEG")
 
74
  raise gr.Error("Sorry, there was a problem getting subject suggestions.")
75
 
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  with gr.Blocks(title="VLM Caption & Annif Demo") as demo:
78
  gr.Markdown("# VLM Caption & Annif Demo")
79
  gr.Markdown(