arxivgpt kim commited on
Commit
7712ec1
1 Parent(s): 6d35cbb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -1,16 +1,29 @@
1
  import gradio as gr
2
  from gradio_client import Client
 
3
 
4
  def get_caption(image_in):
5
  client = Client("https://vikhyatk-moondream1.hf.space/")
6
  result = client.predict(
7
- image_in,
8
- "Describe the image",
9
  api_name="/answer_question"
10
  )
11
- caption = result['choices'][0]['text']
 
 
 
 
 
 
 
 
 
 
 
12
  return caption
13
 
 
14
  def get_lcm(prompt):
15
  client = Client("https://latent-consistency-lcm-lora-for-sdxl.hf.space/")
16
  images = []
 
1
  import gradio as gr
2
  from gradio_client import Client
3
+ import json
4
 
5
  def get_caption(image_in):
6
  client = Client("https://vikhyatk-moondream1.hf.space/")
7
  result = client.predict(
8
+ image_in, # filepath in 'image' Image component
9
+ "Describe the image", # str in 'Question' Textbox component
10
  api_name="/answer_question"
11
  )
12
+
13
+ # JSON 형태로 파싱
14
+ try:
15
+ result_json = json.loads(result)
16
+ caption = result_json['choices'][0]['text']
17
+ except json.JSONDecodeError:
18
+ print("Error: Response is not valid JSON.")
19
+ return ""
20
+ except (KeyError, IndexError):
21
+ print("Error: Invalid format in JSON response.")
22
+ return ""
23
+
24
  return caption
25
 
26
+
27
  def get_lcm(prompt):
28
  client = Client("https://latent-consistency-lcm-lora-for-sdxl.hf.space/")
29
  images = []