Spaces:
Sleeping
Sleeping
RandomOnHuggingFace
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -4,49 +4,41 @@ from huggingface_hub import InferenceClient
|
|
4 |
"""
|
5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
"""
|
7 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
)
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
"""
|
44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
45 |
-
"""
|
46 |
-
demo = gr.ChatInterface(
|
47 |
-
respond,
|
48 |
additional_inputs=[
|
49 |
-
gr.Textbox(value="You are a
|
50 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
51 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
52 |
gr.Slider(
|
@@ -59,6 +51,5 @@ demo = gr.ChatInterface(
|
|
59 |
],
|
60 |
)
|
61 |
|
62 |
-
|
63 |
if __name__ == "__main__":
|
64 |
demo.launch()
|
|
|
4 |
"""
|
5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
"""
|
|
|
7 |
|
8 |
+
# Create InferenceClients for each model (you may need to adjust based on model endpoints)
|
9 |
+
stable_diffusion = InferenceClient("stabilityai/stable-diffusion-3.5-large-turbo")
|
10 |
+
dalle_3 = InferenceClient("ehristoforu/dalle-3-xl-v2")
|
11 |
+
flux = InferenceClient("black-forest-labs/FLUX.1-dev")
|
12 |
+
|
13 |
+
def generate_image(model_choice, prompt, num_images=1):
|
14 |
+
"""Function to generate images based on the chosen model."""
|
15 |
+
if model_choice == "Stable Diffusion 3.5 Large Turbo":
|
16 |
+
response = stable_diffusion.text_to_image(prompt, num_images=num_images)
|
17 |
+
elif model_choice == "DALL路E 3 XL":
|
18 |
+
response = dalle_3.text_to_image(prompt, num_images=num_images)
|
19 |
+
elif model_choice == "FLUX.1-dev":
|
20 |
+
response = flux.text_to_image(prompt, num_images=num_images)
|
21 |
+
|
22 |
+
# Return the generated images (assuming each model returns a URL or image object)
|
23 |
+
return response[0]["image"] # Adjust as needed based on actual response format
|
24 |
+
|
25 |
+
# Create a function to handle user input
|
26 |
+
def generate_image_response(prompt, model_choice):
|
27 |
+
image = generate_image(model_choice, prompt)
|
28 |
+
return image
|
29 |
+
|
30 |
+
# Define Gradio Interface
|
31 |
+
demo = gr.Interface(
|
32 |
+
fn=generate_image_response,
|
33 |
+
inputs=[
|
34 |
+
gr.Textbox(label="Enter your prompt here"),
|
35 |
+
gr.Dropdown(choices=["Stable Diffusion 3.5 Large Turbo", "DALL路E 3 XL", "FLUX.1-dev"], label="Choose Model", value="Stable Diffusion 3.5 Large Turbo")
|
36 |
+
],
|
37 |
+
outputs="image",
|
38 |
+
title="DreamXL Image",
|
39 |
+
description="Welcome to DreamXL Image! Choose a model and input your prompt to generate stunning visuals.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
additional_inputs=[
|
41 |
+
gr.Textbox(value="You are a helpful image generation assistant.", label="System message"),
|
42 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
43 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
44 |
gr.Slider(
|
|
|
51 |
],
|
52 |
)
|
53 |
|
|
|
54 |
if __name__ == "__main__":
|
55 |
demo.launch()
|