Update app.py
Browse files
app.py
CHANGED
|
@@ -401,53 +401,24 @@ async def login(username: str = Form(...), password: str = Form(...), platform:
|
|
| 401 |
except HTTPException as e:
|
| 402 |
return e
|
| 403 |
|
| 404 |
-
def gradio_interface(
|
| 405 |
try:
|
| 406 |
# Suponiendo que el archivo es un CSV con columnas: URL, Count, Delay, Parallel Processes
|
| 407 |
-
import pandas as pd
|
| 408 |
-
df = pd.read_csv(file)
|
| 409 |
-
|
| 410 |
-
if os.getenv(f'{platform.upper()}_USER') and os.getenv(f'{platform.upper()}_PASSWORD'):
|
| 411 |
-
session = authenticate(os.getenv(f'{platform.upper()}_USER'), os.getenv(f'{platform.upper()}_PASSWORD'), platform)
|
| 412 |
-
for index, row in df.iterrows():
|
| 413 |
-
try:
|
| 414 |
-
url = row['URL']
|
| 415 |
-
simulate_views(url, platform, count, delay, parallel_processes, session)
|
| 416 |
-
print(f"Simulation started for row {index}")
|
| 417 |
-
except Exception as e:
|
| 418 |
-
print(f"Error processing row {index}: {e}")
|
| 419 |
-
|
| 420 |
-
return "Simulation completed."
|
| 421 |
-
else:
|
| 422 |
-
return "Credentials not found for this platform."
|
| 423 |
-
except Exception as e:
|
| 424 |
-
return f"Error: {e}"
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
def rand(min, max):
|
| 428 |
-
return random.randint(min, max)
|
| 429 |
-
|
| 430 |
-
def run_simulation(file, platform, count, delay, parallel_processes):
|
| 431 |
-
try:
|
| 432 |
-
# Suponiendo que el archivo es un CSV con columnas: URL, Count, Delay, Parallel Processes
|
| 433 |
-
import pandas as pd
|
| 434 |
-
df = pd.read_csv(file)
|
| 435 |
|
| 436 |
if os.getenv(f'{platform.upper()}_USER') and os.getenv(f'{platform.upper()}_PASSWORD'):
|
| 437 |
session = authenticate(os.getenv(f'{platform.upper()}_USER'), os.getenv(f'{platform.upper()}_PASSWORD'), platform)
|
| 438 |
|
| 439 |
# Create a thread pool executor with maximum workers based on parallel_processes
|
| 440 |
with ThreadPoolExecutor(max_workers=parallel_processes) as executor:
|
| 441 |
-
for index,
|
| 442 |
try:
|
| 443 |
-
url = row['URL']
|
| 444 |
-
|
| 445 |
# Execute the simulate_views function in a separate thread
|
| 446 |
executor.submit(simulate_views, url, platform, count, delay, parallel_processes, session)
|
| 447 |
-
|
| 448 |
-
print(f"Simulation started for row {index}")
|
| 449 |
except Exception as e:
|
| 450 |
-
print(f"Error processing
|
| 451 |
|
| 452 |
return "Simulation completed."
|
| 453 |
else:
|
|
@@ -455,10 +426,14 @@ def run_simulation(file, platform, count, delay, parallel_processes):
|
|
| 455 |
except Exception as e:
|
| 456 |
return f"Error: {e}"
|
| 457 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
gr.Interface(
|
| 459 |
-
fn=
|
| 460 |
inputs=[
|
| 461 |
-
gr.
|
| 462 |
gr.Dropdown(choices=["instagram", "tiktok", "youtube", "facebook", "twitch", "spotify"], label="Platform"),
|
| 463 |
gr.Slider(minimum=1, maximum=1000, label="Count"),
|
| 464 |
gr.Slider(minimum=1, maximum=60, label="Delay (seconds)"),
|
|
|
|
| 401 |
except HTTPException as e:
|
| 402 |
return e
|
| 403 |
|
| 404 |
+
def gradio_interface(urls, platform, count, delay, parallel_processes):
|
| 405 |
try:
|
| 406 |
# Suponiendo que el archivo es un CSV con columnas: URL, Count, Delay, Parallel Processes
|
| 407 |
+
# import pandas as pd
|
| 408 |
+
# df = pd.read_csv(file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 409 |
|
| 410 |
if os.getenv(f'{platform.upper()}_USER') and os.getenv(f'{platform.upper()}_PASSWORD'):
|
| 411 |
session = authenticate(os.getenv(f'{platform.upper()}_USER'), os.getenv(f'{platform.upper()}_PASSWORD'), platform)
|
| 412 |
|
| 413 |
# Create a thread pool executor with maximum workers based on parallel_processes
|
| 414 |
with ThreadPoolExecutor(max_workers=parallel_processes) as executor:
|
| 415 |
+
for index, url in enumerate(urls.split("\n")):
|
| 416 |
try:
|
|
|
|
|
|
|
| 417 |
# Execute the simulate_views function in a separate thread
|
| 418 |
executor.submit(simulate_views, url, platform, count, delay, parallel_processes, session)
|
| 419 |
+
print(f"Simulation started for URL {index+1}: {url}")
|
|
|
|
| 420 |
except Exception as e:
|
| 421 |
+
print(f"Error processing URL {index+1}: {e}")
|
| 422 |
|
| 423 |
return "Simulation completed."
|
| 424 |
else:
|
|
|
|
| 426 |
except Exception as e:
|
| 427 |
return f"Error: {e}"
|
| 428 |
|
| 429 |
+
|
| 430 |
+
def rand(min, max):
|
| 431 |
+
return random.randint(min, max)
|
| 432 |
+
|
| 433 |
gr.Interface(
|
| 434 |
+
fn=gradio_interface,
|
| 435 |
inputs=[
|
| 436 |
+
gr.Textbox(label="Video URLs (one per line)"),
|
| 437 |
gr.Dropdown(choices=["instagram", "tiktok", "youtube", "facebook", "twitch", "spotify"], label="Platform"),
|
| 438 |
gr.Slider(minimum=1, maximum=1000, label="Count"),
|
| 439 |
gr.Slider(minimum=1, maximum=60, label="Delay (seconds)"),
|