arxivgpt kim commited on
Commit
32ea1b8
โ€ข
1 Parent(s): 7712ec1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -41
app.py CHANGED
@@ -1,58 +1,42 @@
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 = []
30
- for _ in range(4): # 4๊ฐœ์˜ ์ด๋ฏธ์ง€ ์ƒ์„ฑ
31
- result = client.predict(
32
- prompt, # str in 'parameter_5' Textbox component
33
- 0.3, # float (numeric value between 0.0 and 5) in 'Guidance' Slider component
34
- 8, # float (numeric value between 2 and 10) in 'Steps' Slider component
35
- 0, # float (numeric value between 0 and 12013012031030) in 'Seed' Slider component
36
- True, # bool in 'Randomize' Checkbox component
37
- api_name="/predict"
38
- )
39
- images.append(result[0])
40
- return images
41
 
42
  def infer(image_in):
43
  caption = get_caption(image_in)
44
- img_vars = get_lcm(caption)
45
- return caption, img_vars
46
 
47
  gr.Interface(
48
- title="ArXivGPT Image",
49
- description=" Image2Image Variation - LCM SDXL & Moondream1 using for image generation",
50
- fn=infer,
51
- inputs=[
52
  gr.Image(type="filepath", label="Image input")
53
  ],
54
- outputs=[
55
- gr.Textbox(label="Caption"),
56
- gr.Gallery(label="LCM Image variations")
57
  ]
58
- ).queue(max_size=25).launch()
 
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
+ results = client.predict(
7
+ prompt, # existing parameters
8
+ num_images=4, # New parameter to request 4 images. This parameter may be different for the actual API.
 
9
  )
10
+ # Print and return the results assuming it contains 4 images
11
+ print(results)
12
+ return results[:4] # Return first 4 images in case the API returns more
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  def get_lcm(prompt):
15
  client = Client("https://latent-consistency-lcm-lora-for-sdxl.hf.space/")
16
+ result = client.predict(
17
+ prompt, # str in 'parameter_5' Textbox component
18
+ 0.3, # float (numeric value between 0.0 and 5) in 'Guidance' Slider component
19
+ 8, # float (numeric value between 2 and 10) in 'Steps' Slider component
20
+ 0, # float (numeric value between 0 and 12013012031030) in 'Seed' Slider component
21
+ True, # bool in 'Randomize' Checkbox component
22
+ api_name="/predict"
23
+ )
24
+ print(result)
25
+ return result[0]
 
 
26
 
27
  def infer(image_in):
28
  caption = get_caption(image_in)
29
+ img_var = get_lcm(caption)
30
+ return img_var
31
 
32
  gr.Interface(
33
+ title = "ArXivGPT Image",
34
+ description = "Image to Image variation, using LCM SDXL & Moondream1",
35
+ fn = infer,
36
+ inputs = [
37
  gr.Image(type="filepath", label="Image input")
38
  ],
39
+ outputs = [
40
+ gr.Image(label="Image variation")
 
41
  ]
42
+ ).queue(max_size=25).launch()