limitedonly41 commited on
Commit
dd5374d
·
verified ·
1 Parent(s): c786964

Update app.py

Browse files

working for 1 url

Files changed (1) hide show
  1. app.py +7 -37
app.py CHANGED
@@ -118,20 +118,14 @@ def classify_website(url):
118
 
119
 
120
  urls = [url]
121
- print(urls)
122
  results_shop = main(urls)
123
 
124
  # Convert results to DataFrame
125
  df_result_train_more = pd.DataFrame(results_shop)
126
- print(df_result_train_more)
127
  text = df_result_train_more['text'][0]
128
- print(text)
129
- try:
130
- translated = GoogleTranslator(source='auto', target='en').translate(text[:4990])
131
- # except:
132
-
133
 
134
- # try:
135
  # Prepare the input prompt for the model
136
  prompt = f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
137
  ### Instruction:
@@ -161,38 +155,14 @@ Categorize the website into one of the 3 categories:
161
  logging.exception(e)
162
  return str(e)
163
 
164
-
165
- def classify_urls_from_csv(csv_file):
166
- # Read CSV file and extract URLs from the first column
167
- df = pd.read_csv(csv_file)
168
- df.iloc[:, 0] = df.iloc[:, 0].str.replace(';', '').str.strip()
169
-
170
- urls = df.iloc[:, 0].tolist()
171
-
172
- # Classify each URL and store the results
173
- predictions = []
174
- for url in urls:
175
- prediction = classify_website(url)
176
- predictions.append(prediction)
177
-
178
- # Add predictions as a new column in the dataframe
179
- df['Prediction'] = predictions
180
-
181
- # Save the results to a new CSV file
182
- output_file = "predictions.csv"
183
- df.to_csv(output_file, index=False)
184
-
185
- return output_file
186
-
187
-
188
  # Create a Gradio interface
189
  iface = gr.Interface(
190
- fn=classify_urls_from_csv,
191
- inputs=gr.File(label="Upload CSV (First column must contain URLs)"),
192
- outputs=gr.File(label="Download CSV with Predictions"),
193
  title="Website Categorization",
194
- description="Upload a CSV file with URLs in the first column and categorize each website into one of the 3 categories: OTHER, NEWS/BLOG, or E-commerce."
195
  )
196
 
197
  # Launch the interface
198
- iface.launch()
 
118
 
119
 
120
  urls = [url]
 
121
  results_shop = main(urls)
122
 
123
  # Convert results to DataFrame
124
  df_result_train_more = pd.DataFrame(results_shop)
 
125
  text = df_result_train_more['text'][0]
126
+ translated = GoogleTranslator(source='auto', target='en').translate(text[:4990])
 
 
 
 
127
 
128
+ try:
129
  # Prepare the input prompt for the model
130
  prompt = f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
131
  ### Instruction:
 
155
  logging.exception(e)
156
  return str(e)
157
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  # Create a Gradio interface
159
  iface = gr.Interface(
160
+ fn=classify_website,
161
+ inputs="text",
162
+ outputs="text",
163
  title="Website Categorization",
164
+ description="Categorize a website into one of the 3 categories: OTHER, NEWS/BLOG, or E-commerce."
165
  )
166
 
167
  # Launch the interface
168
+ iface.launch()