• Namunaviy dastur
  • HTML va CSS
  • Image Description on Hover




    Download 19.28 Kb.
    Sana27.02.2024
    Hajmi19.28 Kb.
    #162962
    Bog'liq
    SICHQONCHA YORDAMIDA TASVIRGA TAVSIF BERISH TEXNOLOGIYALARI PYTHON DASTURI
    Masofaviy ta’lim usullari va texnologiyalari. “O’quv jarayonida masofaviy texnologiyalarni qo’llash.Masofaviy ta’lim tizimlari va texnologiyalar, 5f042dfc86b9b, AZOT xossalari, Atmosfera havosini muhofaza qilish, 1-mavzu, Umumiy fizikadan masalalr tuplami. S. R. Polvonov., 1. Jismlarning erkin tushishi va erkin tushish tezlanishi deb ni, “Tokning magnit maydoni ” mavzusini o’qitishda innavatsion ta’lim texnalogiyalaridan foydalanish metodikasi, inflatsiya riski, 123, 1, Axborot exnalogiyalarining zamonaviy dasturiy ta, C tilida dasturlash, kurs ishi, Milliy va harakatli o`yinlar

    SICHQONCHA YORDAMIDA TASVIRGA TAVSIF BERISH TEXNOLOGIYALARI PYTHON DASTURI
    Pythonda
    Microsoft Azure Computer Vision API kabi oddiy tasvirni qayta ishlash va tavsif kutubxonasidan foydalanaylik.
    Kutubxonalarni o'rnatish: Sizda kutubxonalar pillow(tasvirni qayta ishlash uchun) va requests(Azure Computer Vision API ga so'rov yuborish uchun) o'rnatilganligiga ishonch hosil qiling. Siz ularni buyruqlar yordamida o'rnatishingiz mumkin:

    pip install pillow


    pip install requests

    Namunaviy dastur:

    import tkinter as tk


    from PIL import Image, ImageDraw
    import requests
    from io import BytesIO

    class DrawingApp:


    def __init__(self, root):
    self.root = root
    self.root.title("Drawing and Description App")

    self.canvas = tk.Canvas(root, bg="white", width=400, height=400)


    self.canvas.pack()

    self.image = Image.new("RGB", (400, 400), "white")


    self.draw = ImageDraw.Draw(self.image)

    self.canvas.bind("", self.paint)

    self.description_text = tk.Text(root, height=5, width=50)
    self.description_text.pack()

    self.generate_button = tk.Button(root, text="Generate Description", command=self.generate_description)


    self.generate_button.pack()

    def paint(self, event):


    x1, y1 = (event.x - 1), (event.y - 1)
    x2, y2 = (event.x + 1), (event.y + 1)
    self.canvas.create_oval(x1, y1, x2, y2, fill="black", width=2)
    self.draw.line([x1, y1, x2, y2], fill="black", width=2)

    def generate_description(self):

    # Chizilgan rasmni saqlang

    image_path = "drawing.png"


    self.image.save(image_path)

    # Tasvirni tahlil qilish uchun Azure Computer Vision API-ga yuboring

    subscription_key = 'YOUR_AZURE_SUBSCRIPTION_KEY'
    endpoint = 'YOUR_AZURE_ENDPOINT'
    analyze_url = f"{endpoint}/vision/v3.1/analyze"

    headers = {


    'Ocp-Apim-Subscription-Key': subscription_key,
    'Content-Type': 'application/octet-stream',
    }

    with open(image_path, 'rb') as image_file:


    response = requests.post(analyze_url, headers=headers, files={'file': image_file})

    # Biz tahlil natijasini olamiz va tavsifni matn maydonida ko'rsatamiz

    result = response.json()
    description = ', '.join([tag['name'] for tag in result['description']['tags']])
    self.description_text.delete(1.0, tk.END)
    self.description_text.insert(tk.END, description)

    if __name__ == "__main__":


    root = tk.Tk()
    app = DrawingApp(root)
    root.mainloop()

    Ushbu misol tasvirni tahlil qilish va aniqlangan teglar asosida tavsif yaratish uchun Azure Computer Vision API-dan foydalanadi. Azure hisob ma'lumotlaringiz bilan 'YOUR_AZURE_SUBSCRIPTION_KEY' almashtiring. 'YOUR_AZURE_ENDPOINT'


    HTML+CSS+JawaSript



    HTML va CSS:





    Image <a href="/cmdlet-description.html">Description on Hover</a>





    Image Description








    Download 19.28 Kb.




    Download 19.28 Kb.