arxivgpt kim commited on
Commit
6d35cbb
·
verified ·
1 Parent(s): c563cc2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = []
17
+ for _ in range(4): # 4개의 이미지 생성
18
+ result = client.predict(
19
+ prompt, # str in 'parameter_5' Textbox component
20
+ 0.3, # float (numeric value between 0.0 and 5) in 'Guidance' Slider component
21
+ 8, # float (numeric value between 2 and 10) in 'Steps' Slider component
22
+ 0, # float (numeric value between 0 and 12013012031030) in 'Seed' Slider component
23
+ True, # bool in 'Randomize' Checkbox component
24
+ api_name="/predict"
25
+ )
26
+ images.append(result[0])
27
+ return images
28
+
29
+ def infer(image_in):
30
+ caption = get_caption(image_in)
31
+ img_vars = get_lcm(caption)
32
+ return caption, img_vars
33
+
34
+ gr.Interface(
35
+ title="ArXivGPT Image",
36
+ description=" Image2Image Variation - LCM SDXL & Moondream1 using for image generation",
37
+ fn=infer,
38
+ inputs=[
39
+ gr.Image(type="filepath", label="Image input")
40
+ ],
41
+ outputs=[
42
+ gr.Textbox(label="Caption"),
43
+ gr.Gallery(label="LCM Image variations")
44
+ ]
45
+ ).queue(max_size=25).launch()