dpang commited on
Commit
696bc12
·
1 Parent(s): 69d7f05

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -13
app.py CHANGED
@@ -1,22 +1,72 @@
 
1
  import streamlit as st
 
 
 
2
 
3
- # x = st.slider('Select a value')
4
- # st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- import streamlit as st
7
- import requests
8
 
9
  # Streamlit interface
10
- st.title('POST Request Sender')
11
- url = st.text_input('Enter the URL', 'https://openai.com/completion')
12
- if st.button('Send POST Request'):
13
  # Make a POST request
14
  try:
15
- response = requests.post(url, data={'sample_data': 'value'})
16
- if response.status_code == 200:
17
- st.success('POST request successful!')
18
- st.json(response.json())
19
- else:
20
- st.error(f'Request failed with status code {response.status_code}')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  except Exception as e:
22
  st.error(f'An error occurred: {e}')
 
 
1
+ from googleapiclient.discovery import build
2
  import streamlit as st
3
+ import requests
4
+ from openai import OpenAI
5
+ import os
6
 
7
+ client = OpenAI()
8
+ client.key = os.getenv("OPENAI_API_KEY")
9
+ GOOGLE_API_DEV_KEY = os.getenv("GOOGLE_API_DEV_KEY")
10
+
11
+
12
+ def search_amazon(query: str, num: int = 10) -> str:
13
+ service = build(
14
+ "customsearch", "v1", developerKey=GOOGLE_API_DEV_KEY
15
+ )
16
+
17
+ res = (
18
+ service.cse()
19
+ .list(
20
+ q=query,
21
+ cx="103114c8487ce4aa1",
22
+ num=num,
23
+ )
24
+ .execute()
25
+ )
26
+
27
+ links = ""
28
+
29
+ for item in res['items']:
30
+ links += f"- [{item['title']}]({item['link']})\n"
31
+
32
+ return links
33
 
 
 
34
 
35
  # Streamlit interface
36
+ st.title('Vision Hop')
37
+ url = st.text_input('Enter the image URL', 'Image URL')
38
+ if st.button('Shop'):
39
  # Make a POST request
40
  try:
41
+ response = client.chat.completions.create(
42
+ model="gpt-4-vision-preview",
43
+ messages=[
44
+ {
45
+ "role": "user",
46
+ "content": [
47
+ {"type": "text",
48
+ "text": "Summarize the image as a search string for Amazon.com"},
49
+ # "text": "Identify all the items available to be purchased and for each item list the search terms you would to find them on Amazon.com. Put a number before the search terms"},
50
+
51
+ {
52
+ "type": "image_url",
53
+ "image_url": {
54
+ "url": url,
55
+ },
56
+ },
57
+ ],
58
+ }
59
+ ],
60
+ max_tokens=300,
61
+ )
62
+ search_str = response.choices[0].message.content
63
+ print(search_str)
64
+ st.write(search_str)
65
+
66
+ amazon_output = search_amazon(search_str)
67
+ print(amazon_output)
68
+ st.write(amazon_output)
69
+
70
  except Exception as e:
71
  st.error(f'An error occurred: {e}')
72
+