Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- .github/workflows/update_space.yml +28 -0
- README.md +3 -9
- app.py +101 -0
- requirements.txt +7 -0
.github/workflows/update_space.yml
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Run Python script
|
2 |
+
|
3 |
+
on:
|
4 |
+
push:
|
5 |
+
branches:
|
6 |
+
- main
|
7 |
+
|
8 |
+
jobs:
|
9 |
+
build:
|
10 |
+
runs-on: ubuntu-latest
|
11 |
+
|
12 |
+
steps:
|
13 |
+
- name: Checkout
|
14 |
+
uses: actions/checkout@v2
|
15 |
+
|
16 |
+
- name: Set up Python
|
17 |
+
uses: actions/setup-python@v2
|
18 |
+
with:
|
19 |
+
python-version: '3.9'
|
20 |
+
|
21 |
+
- name: Install Gradio
|
22 |
+
run: python -m pip install gradio
|
23 |
+
|
24 |
+
- name: Log in to Hugging Face
|
25 |
+
run: python -c 'import huggingface_hub; huggingface_hub.login(token="${{ secrets.hf_token }}")'
|
26 |
+
|
27 |
+
- name: Deploy to Spaces
|
28 |
+
run: gradio deploy
|
README.md
CHANGED
@@ -1,12 +1,6 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji: 🌖
|
4 |
-
colorFrom: indigo
|
5 |
-
colorTo: blue
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 4.18.0
|
8 |
app_file: app.py
|
9 |
-
|
|
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: misleading_finall
|
|
|
|
|
|
|
|
|
|
|
3 |
app_file: app.py
|
4 |
+
sdk: gradio
|
5 |
+
sdk_version: 3.44.4
|
6 |
---
|
|
|
|
app.py
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from selenium import webdriver
|
2 |
+
from selenium.webdriver.chrome.options import Options
|
3 |
+
from selenium.webdriver.common.keys import Keys
|
4 |
+
from selenium.webdriver.common.by import By
|
5 |
+
from selenium.webdriver.support.ui import WebDriverWait
|
6 |
+
from selenium.webdriver.support import expected_conditions as EC
|
7 |
+
from gradio_client import Client
|
8 |
+
import json
|
9 |
+
import gradio as gr
|
10 |
+
|
11 |
+
def scrape_data(amazon_url):
|
12 |
+
chrome_options = Options()
|
13 |
+
chrome_options.add_argument("--headless")
|
14 |
+
driver = webdriver.Chrome(options=chrome_options)
|
15 |
+
|
16 |
+
driver.get(amazon_url)
|
17 |
+
|
18 |
+
amazon_title_element = WebDriverWait(driver, 5).until(
|
19 |
+
EC.presence_of_element_located((By.ID, 'productTitle'))
|
20 |
+
)
|
21 |
+
amazon_title = amazon_title_element.text.strip()
|
22 |
+
|
23 |
+
amazon_desc_element = driver.find_element(By.ID, 'feature-bullets')
|
24 |
+
amazon_desc = amazon_desc_element.text.strip()
|
25 |
+
|
26 |
+
driver.get(f'https://www.flipkart.com/search?q={"+".join(amazon_title.split()[:6])}')
|
27 |
+
|
28 |
+
flipkart_url = ''
|
29 |
+
elements = driver.find_elements(By.CLASS_NAME, '_2rpwqI')
|
30 |
+
for element in elements:
|
31 |
+
text_content = element.get_attribute('href')
|
32 |
+
if amazon_title.split()[0].lower() in text_content:
|
33 |
+
flipkart_url = text_content
|
34 |
+
break
|
35 |
+
|
36 |
+
if not flipkart_url:
|
37 |
+
elements = driver.find_elements(By.CLASS_NAME, '_1fQZEK')
|
38 |
+
for element in elements:
|
39 |
+
text_content = element.get_attribute('href')
|
40 |
+
if amazon_title.split()[0].lower() in text_content:
|
41 |
+
flipkart_url = text_content
|
42 |
+
break
|
43 |
+
|
44 |
+
if(flipkart_url.find('flipkart.com') == -1):
|
45 |
+
flipkart_url = 'https://www.flipkart.com' + flipkart_url
|
46 |
+
|
47 |
+
driver.get(flipkart_url)
|
48 |
+
final_elements = driver.find_elements(By.CLASS_NAME, '_2418kt')
|
49 |
+
flipkart_desc = ''
|
50 |
+
for element in final_elements:
|
51 |
+
flipkart_desc = element.text
|
52 |
+
|
53 |
+
driver.quit()
|
54 |
+
|
55 |
+
return amazon_desc, flipkart_desc
|
56 |
+
|
57 |
+
def compare_descriptions(amazon_url):
|
58 |
+
client = Client("https://atulit23-google-flan-t5.hf.space/")
|
59 |
+
|
60 |
+
print(amazon_url)
|
61 |
+
|
62 |
+
amazon_desc, flipkart_desc = scrape_data(amazon_url)
|
63 |
+
|
64 |
+
description_to_compare = "First description: " + amazon_desc + " " + "Second Description: " + flipkart_desc + " As you can see I have provided you with two descriptions. Compare these two descriptions to see if for the same field some different information has been provided. Answer in yes or no."
|
65 |
+
|
66 |
+
print(description_to_compare)
|
67 |
+
|
68 |
+
result = client.predict(
|
69 |
+
description_to_compare,
|
70 |
+
api_name="/predict"
|
71 |
+
)
|
72 |
+
|
73 |
+
final_result = {"Amazon": amazon_desc, "Flipkart": flipkart_desc, "result": ""}
|
74 |
+
if result.find("yes") != -1:
|
75 |
+
final_result["result"] = "Mismatch Detected between the descriptions at Amazon & Flipkart."
|
76 |
+
else:
|
77 |
+
final_result["result"] = "No Mismatch Detected between the descriptions at Amazon & Flipkart."
|
78 |
+
|
79 |
+
return json.dumps(final_result)
|
80 |
+
|
81 |
+
|
82 |
+
inputs_image_url = [
|
83 |
+
gr.Textbox(type="text", label="Topic Name"),
|
84 |
+
]
|
85 |
+
|
86 |
+
outputs_result_dict = [
|
87 |
+
gr.Textbox(type="text", label="Result"),
|
88 |
+
]
|
89 |
+
|
90 |
+
interface_image_url = gr.Interface(
|
91 |
+
fn=compare_descriptions,
|
92 |
+
inputs=inputs_image_url,
|
93 |
+
outputs=outputs_result_dict,
|
94 |
+
title="Text Generation",
|
95 |
+
cache_examples=False,
|
96 |
+
)
|
97 |
+
|
98 |
+
gr.TabbedInterface(
|
99 |
+
[interface_image_url],
|
100 |
+
tab_names=['Some inference']
|
101 |
+
).launch()
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Flask
|
2 |
+
selenium
|
3 |
+
gradio
|
4 |
+
chromedriver-autoinstaller
|
5 |
+
gradio_client
|
6 |
+
uvicorn
|
7 |
+
gunicorn
|