Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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, # filepath in 'image' Image component
|
| 8 |
+
"Describe precisely the image in one sentence.", # str in 'Question' Textbox component
|
| 9 |
+
api_name="/answer_question"
|
| 10 |
+
)
|
| 11 |
+
print(result)
|
| 12 |
+
return result
|
| 13 |
+
|
| 14 |
+
def get_clm(prompt):
|
| 15 |
+
client = Client("https://fffiloni-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
|
| 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 |
+
fn = infer,
|
| 34 |
+
intputs = [
|
| 35 |
+
gr.Image(type="filepath")
|
| 36 |
+
],
|
| 37 |
+
outputs = [
|
| 38 |
+
gr.Image()
|
| 39 |
+
]
|
| 40 |
+
).launch()
|