Phani1008 commited on
Commit
04f6923
·
verified ·
1 Parent(s): 1cbe70b

Update pages/Types of Data.py

Browse files
Files changed (1) hide show
  1. pages/Types of Data.py +95 -23
pages/Types of Data.py CHANGED
@@ -1,25 +1,97 @@
1
- import os
2
- import subprocess
3
- import sys
4
  import streamlit as st
 
 
 
 
 
 
 
5
 
6
- # Install transformers if not already installed
7
- try:
8
- from transformers import pipeline
9
- except ModuleNotFoundError:
10
- subprocess.check_call([sys.executable, "-m", "pip", "install", "transformers"])
11
- from transformers import pipeline
12
-
13
- # Title
14
- st.title("Data Types Analysis with Transformers")
15
-
16
- # User input
17
- user_input = st.text_area("Enter your text here:")
18
-
19
- if user_input:
20
- classifier = pipeline("sentiment-analysis")
21
- result = classifier(user_input)
22
- st.write("### Sentiment Analysis Result:")
23
- st.write(result)
24
- else:
25
- st.write("Please enter some text to analyze.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from streamlit_lottie import st_lottie
3
+ import requests
4
+ from transformers import pipeline
5
+ import gradio as gr
6
+ from PIL import Image, ImageOps
7
+ import numpy as np
8
+ import random
9
 
10
+ # Function to load Lottie animation from a URL
11
+ def load_lottie_url(url: str):
12
+ r = requests.get(url)
13
+ if r.status_code != 200:
14
+ return None
15
+ return r.json()
16
+
17
+ # Load animations using URLs
18
+ structured_animation_url = "https://assets10.lottiefiles.com/packages/lf20_4j6cnjjm.json"
19
+ semi_structured_animation_url = "https://assets10.lottiefiles.com/packages/lf20_0fhcmhgf.json"
20
+ unstructured_animation_url = "https://assets10.lottiefiles.com/packages/lf20_rekwjvy0.json"
21
+
22
+ # Sidebar navigation
23
+ st.sidebar.title("Navigation")
24
+ page = st.sidebar.radio("Choose a page", ["Home", "Structured Data", "Semi-Structured Data", "Unstructured Data", "Image Augmentation"])
25
+
26
+ if page == "Home":
27
+ st.title("Understanding Data and Its Types 🌐")
28
+ st.header("What is Data?")
29
+ st.write("""
30
+ **Data** refers to raw facts, figures, or information that can be collected, measured, and analyzed for specific purposes.
31
+ It serves as the foundation for generating insights, making decisions, and solving problems in various fields.
32
+ """)
33
+
34
+ elif page == "Structured Data":
35
+ st.title("Structured Data 📋")
36
+ animation = load_lottie_url(structured_animation_url)
37
+ if animation:
38
+ st_lottie(animation, height=300, key="structured_animation")
39
+ st.write("""
40
+ **Definition**: Structured data refers to data organized in predefined formats like tables, making it easily searchable.
41
+ """)
42
+
43
+ elif page == "Semi-Structured Data":
44
+ st.title("Semi-Structured Data 🧩")
45
+ animation = load_lottie_url(semi_structured_animation_url)
46
+ if animation:
47
+ st_lottie(animation, height=300, key="semi_structured_animation")
48
+ st.write("""
49
+ **Definition**: Semi-structured data lacks a strict schema but is organized through tags and markers.
50
+ """)
51
+
52
+ elif page == "Unstructured Data":
53
+ st.title("Unstructured Data 🗂️")
54
+ animation = load_lottie_url(unstructured_animation_url)
55
+ if animation:
56
+ st_lottie(animation, height=300, key="unstructured_animation")
57
+ st.write("""
58
+ **Definition**: Unstructured data lacks predefined organization, including images, videos, and audio files.
59
+ """)
60
+
61
+ # Image Augmentation Section
62
+ elif page == "Image Augmentation":
63
+ st.title("Image Augmentation Tool 🖼️")
64
+
65
+ def augment_image(image, crop_size, flip, rotation):
66
+ img = Image.fromarray(image)
67
+ if crop_size > 0:
68
+ width, height = img.size
69
+ left = random.randint(0, crop_size)
70
+ top = random.randint(0, crop_size)
71
+ right = width - random.randint(0, crop_size)
72
+ bottom = height - random.randint(0, crop_size)
73
+ img = img.crop((left, top, right, bottom))
74
+ if flip:
75
+ img = ImageOps.mirror(img)
76
+ if rotation != 0:
77
+ img = img.rotate(rotation, expand=True)
78
+ return np.array(img)
79
+
80
+ def interface(image, crop_size, flip, rotation):
81
+ augmented_image = augment_image(image, crop_size, flip, rotation)
82
+ return augmented_image
83
+
84
+ app = gr.Interface(
85
+ fn=interface,
86
+ inputs=[
87
+ gr.Image(type="numpy"),
88
+ gr.Slider(0, 100, step=1, label="Crop Size"),
89
+ gr.Checkbox(label="Flip"),
90
+ gr.Slider(0, 360, step=1, label="Rotation Angle")
91
+ ],
92
+ outputs=gr.Image(type="numpy"),
93
+ title="Image Augmentation Tool",
94
+ description="Upload an image to apply cropping, flipping, and rotation."
95
+ )
96
+
97
+ app.launch()