Spaces:
Runtime error
Runtime error
Kvikontent
commited on
Commit
•
e336bcd
1
Parent(s):
f2f716e
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import io
|
4 |
+
from PIL import Image
|
5 |
+
import os
|
6 |
+
import random
|
7 |
+
import faker
|
8 |
+
|
9 |
+
# Setting up API endpoints and headers
|
10 |
+
face_api_url = "https://api-inference.huggingface.co/models/stablediffusionapi/realvis-xl-v40"
|
11 |
+
fingerprint_api_url = "https://api-inference.huggingface.co/models/Kvikontent/Fingerprints-V1"
|
12 |
+
headers = {"Authorization": f"Bearer {os.environ['hf_token']}"}
|
13 |
+
|
14 |
+
# Function to query the face generation API
|
15 |
+
def generate_face_image(age, gender):
|
16 |
+
response = requests.post(face_api_url, headers=headers, json={"inputs": f"Photo of {age} years old {gender} with serious face"})
|
17 |
+
return Image.open(io.BytesIO(response.content))
|
18 |
+
|
19 |
+
# Function to generate a random name
|
20 |
+
def generate_random_name(gender):
|
21 |
+
fake = faker.Faker()
|
22 |
+
if gender == "Male":
|
23 |
+
return fake.first_name_male()
|
24 |
+
else:
|
25 |
+
return fake.first_name_female()
|
26 |
+
|
27 |
+
# Function to generate a random surname
|
28 |
+
def generate_random_surname():
|
29 |
+
fake = faker.Faker()
|
30 |
+
return fake.last_name()
|
31 |
+
|
32 |
+
# Function to generate a random birth date
|
33 |
+
def generate_random_birth_date():
|
34 |
+
fake = faker.Faker()
|
35 |
+
return fake.date_of_birth().strftime("%m/%d/%Y")
|
36 |
+
|
37 |
+
# Function to generate a random 6-digit number for fingerprint generation
|
38 |
+
def generate_random_number():
|
39 |
+
return random.randint(100000, 999999)
|
40 |
+
|
41 |
+
# Function to query the fingerprint generation API
|
42 |
+
def generate_fingerprint(number):
|
43 |
+
response = requests.post(fingerprint_api_url, headers=headers, json={"inputs": f"Fingerprint of {number}"})
|
44 |
+
return Image.open(io.BytesIO(response.content))
|
45 |
+
|
46 |
+
# Streamlit app layout
|
47 |
+
st.title("Random Data Generator App")
|
48 |
+
st.header("Generate Random Data")
|
49 |
+
|
50 |
+
# Gender selection input
|
51 |
+
gender = st.selectbox("Select Gender", ["Male", "Female"])
|
52 |
+
|
53 |
+
# Generate random name, surname, and birth date
|
54 |
+
name = generate_random_name(gender)
|
55 |
+
surname = generate_random_surname()
|
56 |
+
birth_date = generate_random_birth_date()
|
57 |
+
|
58 |
+
st.write(f"Name: {name}")
|
59 |
+
st.write(f"Surname: {surname}")
|
60 |
+
st.write(f"Birth Date: {birth_date}")
|
61 |
+
|
62 |
+
# Generate face image based on age
|
63 |
+
age = 30
|
64 |
+
st.write(f"Photo of {age} years old {gender} with serious face:")
|
65 |
+
face_image = generate_face_image(age, gender)
|
66 |
+
st.image(face_image, caption=f"{age} years old {gender}")
|
67 |
+
|
68 |
+
# Generate random 6-digit number and display fingerprint
|
69 |
+
random_number = generate_random_number()
|
70 |
+
st.write(f"Fingerprint of {random_number}:")
|
71 |
+
fingerprint_image = generate_fingerprint(random_number)
|
72 |
+
st.image(fingerprint_image, caption=f"Fingerprint of {random_number}")
|