File size: 5,071 Bytes
3065c83
800bc06
 
f81c34b
 
 
 
 
 
 
 
 
 
 
 
3065c83
f81c34b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
800bc06
44c8a81
de8ad27
800bc06
44c8a81
f81c34b
44c8a81
4a7839c
 
c669fd1
573586a
f81c34b
 
 
 
 
 
 
573586a
 
f81c34b
573586a
4a7839c
 
f81c34b
c669fd1
 
 
 
 
 
f81c34b
 
 
 
 
 
 
 
 
 
 
 
c669fd1
800bc06
4a7839c
 
f81c34b
4a7839c
f81c34b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import streamlit as st
from transformers import pipeline
from PIL import Image
from rembg import remove
from io import BytesIO
from ebay import search_ebay_sold_items
from llava import get_quality
from os.path import abspath
import os
from anthropic import Anthropic, HUMAN_PROMPT, AI_PROMPT
import re
def convert_string_to_dict(data_string):
    pairs = re.findall(r'"([^"]+)"\s*:\s*"([^"]*)"', data_string)
    data_dictionary = dict(pairs)
    return data_dictionary

def improving_picture(file_name):
    image = file_name.getvalue()
    new_image = remove(image, alpha_matting=True)
    return new_image
def add_white_background_to_image_bytes(modified_image_bytes):
    # Convert bytes to PIL Image
    modified_image = Image.open(BytesIO(modified_image_bytes))
    
    # Create a new image with a white background of the same size as the modified image
    new_image = Image.new("RGB", modified_image.size, "white")
    
    # Paste the modified image onto the white background
    new_image.paste(modified_image, (0, 0), modified_image)
    
    # Convert the new image to bytes
    output_image_bytes = BytesIO()
    new_image.save(output_image_bytes, format='PNG')  # Change format if needed
    
    return output_image_bytes.getvalue()
def find_brackets_indices(s):
    first_open_bracket = s.find("{")
    
    if first_open_bracket != -1:
        second_last_close_bracket = s.rfind("}", first_open_bracket + 1, len(s) - 1)
        return first_open_bracket, second_last_close_bracket
    else:
        return -1, -1  # Return -1 if "{" is not found
#pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")

# Set the title and text color to dark green
st.markdown('<h1 style="color:darkgreen;">R3SELL</h1>', unsafe_allow_html=True)

# Create a file input option for uploading an image
file_name = st.file_uploader("Upload an image file (JPEG, PNG, etc.)", type=["png", "jpg", "jpeg"])

# Create a camera input widget to capture images from the webcam
image = st.camera_input("Capture an image from your webcam")

# Add a text bar to add a title
image_title = st.text_input("Image Title")
price = 'Prices: '
if image_title != '':
    price = 'Prices: ' + str(search_ebay_sold_items(image_title))
    st.write(price)
else:
    st.write(price)

# Add a text bar to add a description
#mage_description = st.text_input("Image Description", value="(Optional)")

if file_name is not None or image is not None:
    # Check if the image is a webcam image

    if file_name == 'webcam_image.jpg':
        # Use the Base64 encoded image
        image = Image.open('data:image/jpeg;base64,' + img_encoded)
    else:
        # Open the uploaded image
        image = Image.open(file_name)
        
        nameFile = file_name.name
        def save_uploaded_image_locally(uploaded_file):
            if uploaded_file is not None:
                file_path = os.path.join(".", uploaded_file.name)
                with open(file_path, "wb") as f:
                    f.write(uploaded_file.getbuffer())
        save_uploaded_image_locally(file_name)
        st.write('Description: ' + get_quality(abspath(nameFile))[5:])
        st.write('')
        st.write('<span style="font-size: 36px;">Modified Image with White Background </span>', unsafe_allow_html=True)
        image_rem = add_white_background_to_image_bytes(improving_picture(file_name))




    st.image(image_rem, use_column_width=True)

anthropic = Anthropic(
    api_key="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",
)
name = str(image_title)
description = "get_quality(abspath(nameFile))[5:]"
output_price = str(price)
s = "Name of Product is "+ name +". Min, 1st quartile, median, 3rd quartile, and max of used prices are "+ price +". Assume max is best used quality and min in worst used quality. Color and defects(consider in price and description) -  "+description+"(sub color with official colorname). Generate a price given previous which ends in .99. Feel free to search the web. Video should be a product/review video make sure video is real. Generate a product description and the relevant information for an ebay listing. Search the web for additional help and it should be good for the ebay algorithms. Give it as a JSON with these categories Product Name, Price, Condition, Brand, Type, Color, Description, Specifications, Size, Video, Department. Generate Facebook and Instagram ads with hashtags and other stuff to boost algorithm. "
promp = "\n\nHuman ${userQuestion}\n\nAssistant:"
completion = anthropic.completions.create(
    model="claude-2",
    max_tokens_to_sample=1000,
    prompt=f"{HUMAN_PROMPT} "+s+f" {AI_PROMPT}",
)
first_index, second_to_last_index = find_brackets_indices(completion.completion)
string_data = completion.completion[first_index:second_to_last_index + 1]
print(list(convert_string_to_dict(string_data).values()))
for key, value in convert_string_to_dict(string_data).items():
    st.write(f'{key}: {value}')
st.write(completion.completion[second_to_last_index + 1:])