import gradio as gr import numpy as np import random from diffusers import DiffusionPipeline import torch device = "cuda" if torch.cuda.is_available() else "cpu" if torch.cuda.is_available(): torch.cuda.max_memory_allocated(device=device) pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16", use_safetensors=True) pipe.enable_xformers_memory_efficient_attention() pipe = pipe.to(device) else: pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True) pipe = pipe.to(device) MAX_SEED = np.iinfo(np.int32).max MAX_IMAGE_SIZE = 1024 def infer_image(image): # Buraya geolocation tahmin işlevi eklenecek return "Geolocation prediction result here" def Analyse_social_media(text): # Sosyal medya analiz işlevi burada olacak (dummy fonksiyon) return f"Analysed social media text: {text}" def Analyse_webpage(url): # Web sayfası analiz işlevi burada olacak (dummy fonksiyon) return f"Analysed webpage URL: {url}" css = """ #col-container { margin: 0 auto; max-width: 520px; } """ power_device = "GPU" if torch.cuda.is_available() else "CPU" with gr.Blocks(css=css) as demo: with gr.Column(elem_id="col-container"): gr.Markdown(f""" # Geolocation Guesstimation App Welcome to the Geolocation Predictor. Please select an action from the sidebar dropdown. """) with gr.Tabs(): with gr.Tab("Image Analysis"): with gr.Row(): image_input = gr.Image(label="Upload Image", type="pil") run_button_image = gr.Button("Analyse") result_image = gr.Textbox(label="Result") run_button_image.click( fn=infer_image, inputs=[image_input], outputs=[result_image] ) with gr.Tab("Social Media Analysis"): social_media_text = gr.Textbox( label="Social Media Text", placeholder="Enter text for social media analysis" ) run_button_social = gr.Button("Analyse") result_social = gr.Textbox(label="Result") run_button_social.click( fn=Analyse_social_media, inputs=[social_media_text], outputs=[result_social] ) with gr.Tab("Webpage Analysis"): webpage_url = gr.Textbox( label="Webpage URL", placeholder="Enter URL for webpage analysis" ) run_button_webpage = gr.Button("Analyse") result_webpage = gr.Textbox(label="Result") run_button_webpage.click( fn=Analyse_webpage, inputs=[webpage_url], outputs=[result_webpage] ) demo.queue().launch()