RandomOnHuggingFace commited on
Commit
fcbf8c9
verified
1 Parent(s): f98f11b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -42
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
- def respond(
11
- message,
12
- history: list[tuple[str, str]],
13
- system_message,
14
- max_tokens,
15
- temperature,
16
- top_p,
17
- ):
18
- messages = [{"role": "system", "content": system_message}]
19
-
20
- for val in history:
21
- if val[0]:
22
- messages.append({"role": "user", "content": val[0]})
23
- if val[1]:
24
- messages.append({"role": "assistant", "content": val[1]})
25
-
26
- messages.append({"role": "user", "content": message})
27
-
28
- response = ""
29
-
30
- for message in client.chat_completion(
31
- messages,
32
- max_tokens=max_tokens,
33
- stream=True,
34
- temperature=temperature,
35
- top_p=top_p,
36
- ):
37
- token = message.choices[0].delta.content
38
-
39
- response += token
40
- yield response
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 friendly Chatbot.", label="System message"),
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()