Ifeanyi commited on
Commit
bef155a
1 Parent(s): ad59256

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -28
app.py CHANGED
@@ -1,31 +1,34 @@
1
- from diffusers import StableDiffusionXLPipeline
2
  import gradio as gr
3
- import torch
4
-
5
- #from transformers.utils.hub import move_cache
6
- import pkg_resources
7
- #move_cache()
8
-
9
- print("------------------------")
10
- package_name = "transformers"
11
- version = pkg_resources.get_distribution(package_name).version
12
- print(f"The version of {package_name} is: {version}")
13
- print("------------------------")
14
-
15
- def segMindImage(prompt, negative_prompt):
16
- pipe = StableDiffusionXLPipeline.from_pretrained("segmind/SSD-1B", torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
17
- pipe.to("cuda")
18
- prompt = prompt # Your prompt here
19
- neg_prompt = negative_prompt # Negative prompt here
20
- image = pipe(prompt=prompt, negative_prompt=neg_prompt).images[0]
21
-
22
- return image
23
-
24
- app = gr.Interface(segMindImage,
25
- inputs = [gr.Text(label="Prompt",placeholder="Write Prompt"),gr.Text(label="Negative Prompt",placeholder="Write Negative Prompt")],
26
- outputs = gr.Image(label="Image"),
27
- css =".gradio-container {background-image: linear-gradient(#7F7FD5, #91EAE4, #A3C9E2)}",
28
- theme = gr.themes.Soft(),
29
- title = "SD Image Diffusion")
 
30
 
31
  app.launch()
 
 
 
1
+ import google.generativeai as genai
2
  import gradio as gr
3
+ import numpy as np
4
+ import PIL.Image
5
+
6
+ genai.configure(api_key="AIzaSyAj-b3sO_wUguMdpXWScxKzMHxb8C5cels")
7
+
8
+ def ImageChat(image):
9
+
10
+ # load model
11
+ model = genai.GenerativeModel("gemini-pro-vision")
12
+
13
+ # check image file and convert to a Numpy array
14
+ if isinstance(image, np.ndarray):
15
+
16
+ img = PIL.Image.fromarray(image)
17
+ else:
18
+ img = PIL.Image.open(image)
19
+
20
+ response = model.generate_content(["write a short, exciting, captivating, and funny adventure story about the image", img])
21
+
22
+ return response.text
23
+
24
+
25
+ app = gr.Interface(ImageChat,
26
+ inputs = gr.Image(),
27
+ outputs = gr.Text(),
28
+ title = "Image-To-Story",
29
+ theme = gr.themes.Soft())
30
+
31
 
32
  app.launch()
33
+
34
+