Spaces:
Running
Running
aakashch0179
commited on
Commit
•
24fcc2a
1
Parent(s):
aa18b07
Update app.py
Browse files
app.py
CHANGED
@@ -302,131 +302,164 @@
|
|
302 |
# Fbgroup
|
303 |
|
304 |
|
305 |
-
from selenium import webdriver
|
306 |
-
from selenium.webdriver.common.by import By
|
307 |
-
from selenium.webdriver.common.keys import Keys
|
308 |
-
import time
|
309 |
-
from time import sleep
|
310 |
-
from selenium.webdriver.chrome.options import Options
|
311 |
-
from selenium.webdriver.chrome.service import Service
|
312 |
-
from webdriver_manager.chrome import ChromeDriverManager
|
313 |
-
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
314 |
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
)
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
time.sleep(6)
|
423 |
-
post_button = driver.find_element_by_xpath("//*[@data-testid='react-composer-post-button']")
|
424 |
-
# ... (Rest of your logic to click the post button)
|
425 |
-
|
426 |
-
driver.close()
|
427 |
-
|
428 |
-
if __name__ == '__main__':
|
429 |
-
main()
|
430 |
-
|
431 |
-
|
432 |
-
|
|
|
302 |
# Fbgroup
|
303 |
|
304 |
|
305 |
+
# from selenium import webdriver
|
306 |
+
# from selenium.webdriver.common.by import By
|
307 |
+
# from selenium.webdriver.common.keys import Keys
|
308 |
+
# import time
|
309 |
+
# from time import sleep
|
310 |
+
# from selenium.webdriver.chrome.options import Options
|
311 |
+
# from selenium.webdriver.chrome.service import Service
|
312 |
+
# from webdriver_manager.chrome import ChromeDriverManager
|
313 |
+
# import streamlit as st
|
314 |
+
|
315 |
+
# import setuptools
|
316 |
+
|
317 |
+
# with open("README.md", encoding="utf-8") as readme_file:
|
318 |
+
# readme = readme_file.read()
|
319 |
+
|
320 |
+
# setuptools.setup(
|
321 |
+
# name='webdriver_manager',
|
322 |
+
# python_requires=">=3.7",
|
323 |
+
# long_description=readme,
|
324 |
+
# long_description_content_type="text/markdown",
|
325 |
+
# packages=setuptools.find_packages(include=['webdriver_manager*']),
|
326 |
+
# include_package_data=True,
|
327 |
+
# version='4.0.1',
|
328 |
+
# description='Library provides the way to automatically manage drivers for different browsers',
|
329 |
+
# author='Sergey Pirogov',
|
330 |
+
# author_email='automationremarks@gmail.com',
|
331 |
+
# url='https://github.com/SergeyPirogov/webdriver_manager',
|
332 |
+
# keywords=['testing', 'selenium', 'driver', 'test automation'],
|
333 |
+
# classifiers=[
|
334 |
+
# 'License :: OSI Approved :: Apache Software License',
|
335 |
+
# 'Intended Audience :: Information Technology',
|
336 |
+
# 'Intended Audience :: Developers',
|
337 |
+
# 'Programming Language :: Python :: 3.7',
|
338 |
+
# 'Programming Language :: Python :: 3.8',
|
339 |
+
# 'Programming Language :: Python :: 3.9',
|
340 |
+
# 'Programming Language :: Python :: 3.10',
|
341 |
+
# 'Programming Language :: Python :: 3.11',
|
342 |
+
# 'Topic :: Software Development :: '
|
343 |
+
# 'Libraries :: Python Modules',
|
344 |
+
# 'Operating System :: Microsoft :: Windows',
|
345 |
+
# 'Operating System :: POSIX',
|
346 |
+
# 'Operating System :: Unix',
|
347 |
+
# 'Operating System :: MacOS',
|
348 |
+
# ],
|
349 |
+
# install_requires=[
|
350 |
+
# 'requests',
|
351 |
+
# 'python-dotenv',
|
352 |
+
# 'packaging'
|
353 |
+
# ],
|
354 |
+
# package_data={
|
355 |
+
# "webdriver_manager": ["py.typed"]
|
356 |
+
# },
|
357 |
+
# )
|
358 |
|
359 |
+
|
360 |
+
# def main():
|
361 |
+
# # Input fields
|
362 |
+
# st.title("Facebook Group Poster")
|
363 |
+
# account = st.text_input("Facebook Account Email", "sample@gmail.com")
|
364 |
+
# password = st.text_input("Facebook Password", "sample", type="password")
|
365 |
+
# groups_links_list = st.text_area("Facebook Group URLs (one per line)",
|
366 |
+
# "https://www.facebook.com/groups/sample1\nhttps://www.facebook.com/groups/sample2")
|
367 |
+
# message = st.text_area("Post Message", "Checkout this amazing script...")
|
368 |
+
# images_list = st.file_uploader("Upload Images", accept_multiple_files=True)
|
369 |
+
|
370 |
+
# if st.button('Post to Facebook Groups'):
|
371 |
+
# if not account or not password or not groups_links_list or not message or not images_list:
|
372 |
+
# st.error("Please fill all the fields.")
|
373 |
+
# else:
|
374 |
+
# chrome_options = Options()
|
375 |
+
# prefs = {"profile.default_content_setting_values.notifications": 2}
|
376 |
+
# chrome_options.add_experimental_option("prefs", prefs)
|
377 |
+
|
378 |
+
# with st.spinner("Posting to Facebook..."):
|
379 |
+
# driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)
|
380 |
+
# driver.get('https://www.facebook.com')
|
381 |
+
|
382 |
+
# # Login Logic (Replace XPaths if needed)
|
383 |
+
# emailelement = driver.find_element(By.XPATH,'//*[@id="email"]')
|
384 |
+
# emailelement.send_keys(account)
|
385 |
+
# passelement = driver.find_element(By.XPATH,'//*[@id="pass"]')
|
386 |
+
# passelement.send_keys(password)
|
387 |
+
# loginelement = driver.find_element(By.XPATH,'//*[@id="loginbutton"]')
|
388 |
+
# loginelement.click()
|
389 |
+
|
390 |
+
# # Posting Logic
|
391 |
+
# groups_links = groups_links_list.splitlines()
|
392 |
+
|
393 |
+
# for group in groups_links:
|
394 |
+
# driver.get(group)
|
395 |
+
# time.sleep(2)
|
396 |
+
|
397 |
+
# try:
|
398 |
+
# driver.find_element(By.XPATH,'//*[@label="Start Discussion"]').click()
|
399 |
+
# post_box=driver.find_element_by_css_selector("[name='xhpc_message_text']")
|
400 |
+
# except:
|
401 |
+
# post_box=driver.find_element_by_css_selector("[name='xhpc_message_text']")
|
402 |
+
# post_box.send_keys(message)
|
403 |
+
|
404 |
+
# time.sleep(1)
|
405 |
+
|
406 |
+
# # Image Upload Logic (Adapt based on Streamlit setup)
|
407 |
+
# for image_file in images_list:
|
408 |
+
# photo_element = driver.find_element(By.XPATH,'//input[@type="file"]')
|
409 |
+
# image_path = image_file.name # Placeholder! Adjust how you get the path
|
410 |
+
# photo_element.send_keys(image_path)
|
411 |
+
# time.sleep(1)
|
412 |
+
|
413 |
+
# # time.sleep(6)
|
414 |
+
# # post_button = driver.find_element_by_xpath("//*[@data-testid='react-composer-post-button']")
|
415 |
+
|
416 |
+
# # Handle image uploads (assuming one upload field per image)
|
417 |
+
# for image_file in images_list:
|
418 |
+
# photo_element = driver.find_element(By.XPATH,'//input[@type="file"]')
|
419 |
+
# photo_element.send_keys(image_file.name) # Or image_file.path, adjust as needed
|
420 |
+
# time.sleep(1)
|
421 |
+
|
422 |
+
# time.sleep(6)
|
423 |
+
# post_button = driver.find_element_by_xpath("//*[@data-testid='react-composer-post-button']")
|
424 |
+
# # ... (Rest of your logic to click the post button)
|
425 |
+
|
426 |
+
# driver.close()
|
427 |
+
|
428 |
+
# if __name__ == '__main__':
|
429 |
+
# main()
|
430 |
+
|
431 |
+
# text to Image
|
432 |
+
|
433 |
+
import streamlit as st
|
434 |
+
import torch
|
435 |
+
from diffusers import StableDiffusionXLPipeline, UNet2DConditionModel, EulerDiscreteScheduler
|
436 |
+
from huggingface_hub import hf_hub_download
|
437 |
+
from safetensors.torch import load_file
|
438 |
+
|
439 |
+
# Model Path/Repo Information
|
440 |
+
base = "stabilityai/stable-diffusion-xl-base-1.0"
|
441 |
+
repo = "ByteDance/SDXL-Lightning"
|
442 |
+
ckpt = "sdxl_lightning_4step_unet.safetensors"
|
443 |
+
|
444 |
+
# Load model (Executed only once for efficiency)
|
445 |
+
@st.cache_resource
|
446 |
+
def load_sdxl_pipeline():
|
447 |
+
unet = UNet2DConditionModel.from_config(base, subfolder="unet").to("cuda", torch.float16)
|
448 |
+
unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device="cuda"))
|
449 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=torch.float16, variant="fp16").to("cuda")
|
450 |
+
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")
|
451 |
+
return pipe
|
452 |
+
|
453 |
+
# Streamlit UI
|
454 |
+
st.title("Stable Diffusion XL Image Generation")
|
455 |
+
prompt = st.text_input("Enter your image prompt:")
|
456 |
+
|
457 |
+
if st.button("Generate Image"):
|
458 |
+
if not prompt:
|
459 |
+
st.warning("Please enter a prompt.")
|
460 |
+
else:
|
461 |
+
pipe = load_sdxl_pipeline() # Load the pipeline from cache
|
462 |
+
with torch.no_grad():
|
463 |
+
image = pipe(prompt).images[0]
|
464 |
+
|
465 |
+
st.image(image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|