antfraia commited on
Commit
3b82cbc
·
0 Parent(s):

Duplicate from ridges/AmazonReviews

Browse files
Files changed (4) hide show
  1. .gitattributes +35 -0
  2. README.md +14 -0
  3. app.py +57 -0
  4. requirements.txt +4 -0
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: AmazonReviews
3
+ emoji: 🐠
4
+ colorFrom: pink
5
+ colorTo: blue
6
+ sdk: gradio
7
+ sdk_version: 3.41.2
8
+ app_file: app.py
9
+ pinned: false
10
+ license: other
11
+ duplicated_from: ridges/AmazonReviews
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ # Function to get Amazon reviews
5
+ def get_reviews(asin, domain):
6
+ payload = {
7
+ 'source': 'amazon_reviews',
8
+ 'domain': domain,
9
+ 'query': asin,
10
+ 'parse': True,
11
+ 'start_page': 1,
12
+ }
13
+
14
+ if domain == 'it':
15
+ payload['geo_location'] = '20144'
16
+
17
+ response = requests.request(
18
+ 'POST',
19
+ 'https://realtime.oxylabs.io/v1/queries',
20
+ auth=('antonces', 'APIusertest23'),
21
+ json=payload,
22
+ )
23
+
24
+ return response.json() if response.status_code == 200 else None
25
+
26
+ # Gradio Function
27
+ def amazon_review_interface(asin, domain):
28
+ reviews = get_reviews(asin, domain)
29
+ review_texts = [review['content'] for review in reviews['results'][0]['content']['reviews']]
30
+
31
+ # Limit to top 5 reviews
32
+ review_texts = review_texts[:5]
33
+
34
+ # Convert to DataFrame for structured tabular format
35
+ df_reviews = pd.DataFrame({'Reviews': review_texts})
36
+
37
+ return df_reviews
38
+
39
+ # Gradio Interface
40
+ inputs = [
41
+ gr.Textbox(placeholder="Enter ASIN", label="Amazon ASIN"),
42
+ gr.Dropdown(choices=['co.uk', 'de', 'fr', 'it', 'es', 'nl', 'pl', 'se'], label="Select Domain")
43
+ ]
44
+
45
+ outputs = [
46
+ gr.Dataframe(label="Amazon Reviews")
47
+ ]
48
+
49
+ iface = gr.Interface(
50
+ fn=amazon_review_interface,
51
+ inputs=inputs,
52
+ outputs=outputs,
53
+ theme="monochrome",
54
+ description="Enter the Amazon ASIN and select the domain to get the top reviews in a structured table format."
55
+ )
56
+
57
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ requests
3
+ transformers
4
+ torch