gundala31yash commited on
Commit
a5bc641
1 Parent(s): 4697a57

First model version

Browse files
Files changed (2) hide show
  1. push.py +8 -0
  2. trial1.py +75 -0
push.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from transformers import Trainer
2
+
3
+ # Assuming your Trainer object is called 'trainer'
4
+ Trainer.push_to_hub(
5
+ "ranga-godhandaraman/avatar-generator-women", # Replace with your details
6
+ overwrite=True # Set overwrite to True to update existing version (optional)
7
+ )
8
+
trial1.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+ import requests
4
+ import torch
5
+ import random
6
+ import numpy as np
7
+ from diffusers import StableDiffusionInstructPix2PixPipeline, EulerAncestralDiscreteScheduler
8
+
9
+ # Load the model
10
+ model_id = "/home/gopinath28031995/yashwanth/projects/watermark_env/instruction-tuned-sd/woman-avatar-gen"
11
+ pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
12
+ pipe.to("cuda")
13
+ pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
14
+
15
+ # Function to download image from URL
16
+ def download_image(url):
17
+ image = Image.open(requests.get(url, stream=True).raw)
18
+ # Handle image orientation
19
+ if hasattr(image, '_getexif'):
20
+ exif = image._getexif()
21
+ if exif is not None:
22
+ orientation = exif.get(0x0112)
23
+ if orientation is not None:
24
+ if orientation == 3:
25
+ image = image.rotate(180, expand=True)
26
+ elif orientation == 6:
27
+ image = image.rotate(270, expand=True)
28
+ elif orientation == 8:
29
+ image = image.rotate(90, expand=True)
30
+ image = image.convert("RGB")
31
+ return image
32
+
33
+ # Streamlit app
34
+ st.title("Instruct Pix2Pix Image Generation")
35
+
36
+ # Add drag and drop/upload image options
37
+ uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
38
+ image_url = st.text_input("Enter image URL")
39
+
40
+ # Input prompt from user
41
+ prompt = st.text_input("Enter prompt", "Generate a fantasy version, retain hair and facial features, 8k")
42
+
43
+ # Input seed, steps, and configuration scales from the user
44
+ seed = st.number_input("Seed", value=42, step=1)
45
+ num_inference_steps = st.number_input("Number of Inference Steps", value=300, step=10, min_value=0)
46
+ text_cfg_scale = st.number_input("Text CFG Scale", value=3.0, step=0.1, min_value=0.0)
47
+ image_cfg_scale = st.number_input("Image CFG Scale", value=7.5, step=0.1, min_value=0.0)
48
+
49
+ if uploaded_file is not None:
50
+ # Display the uploaded image
51
+ image = Image.open(uploaded_file)
52
+ st.image(image, caption="Uploaded Image", use_column_width=True)
53
+ elif image_url:
54
+ # Download and display image from URL
55
+ try:
56
+ image = download_image(image_url)
57
+ st.image(image, caption="Image from URL", use_column_width=True)
58
+ except Exception as e:
59
+ st.error("Error downloading image from URL. Please make sure the URL is correct.")
60
+ else:
61
+ # Use default image URL
62
+ url = "https://raw.githubusercontent.com/timothybrooks/instruct-pix2pix/main/imgs/example.jpg"
63
+ st.write("Using default image.")
64
+ image = download_image(url)
65
+
66
+ # Generate image based on the user input
67
+ if st.button("Generate"):
68
+ # Generate image
69
+ generated_images = pipe(prompt,
70
+ image=image,
71
+ num_inference_steps=num_inference_steps,
72
+ image_cfg=image_cfg_scale,
73
+ text_cfg_scale=text_cfg_scale,
74
+ seed=seed)
75
+ st.image(generated_images[0], caption="Generated Image", use_column_width=True)