|
import gradio as gr |
|
from PIL import Image |
|
import requests |
|
from io import BytesIO |
|
import os |
|
|
|
|
|
def process_image(image, prompt): |
|
|
|
image_data = image.read() |
|
|
|
|
|
headers = { |
|
"Authorization": f"Bearer {os.getenv('HF_TOKEN')}" |
|
} |
|
data = { |
|
"inputs": { |
|
"image": image_data, |
|
"prompt": prompt |
|
} |
|
} |
|
response = requests.post("https://api-inference.huggingface.co/models/CrucibleAI/ControlNetMediaPipeFace", headers=headers, files=data) |
|
|
|
|
|
if response.status_code == 200: |
|
|
|
image = Image.open(BytesIO(response.content)) |
|
return image |
|
else: |
|
|
|
return f"Error: {response.text}" |
|
|
|
|
|
with gr.Blocks() as demo: |
|
with gr.Row(): |
|
with gr.Column(): |
|
image_input = gr.Image(type="pil", label="Upload Image") |
|
prompt_input = gr.Textbox(label="Enter Prompt") |
|
with gr.Column(): |
|
output_image = gr.Image(type="pil", label="Output Image") |
|
|
|
submit_button = gr.Button("Submit") |
|
submit_button.click(fn=process_image, inputs=[image_input, prompt_input], outputs=output_image) |
|
|
|
|
|
demo.launch() |