Spaces:
Runtime error
Runtime error
import streamlit as st | |
import requests | |
import io | |
from PIL import Image | |
import os | |
import random | |
import faker | |
import datetime | |
# Setting up API endpoints and headers | |
face_api_url = "https://api-inference.huggingface.co/models/stablediffusionapi/realvis-xl-v40" | |
fingerprint_api_url = "https://api-inference.huggingface.co/models/Kvikontent/Fingerprints-V1" | |
headers = {"Authorization": f"Bearer {os.environ['hf_token']}"} | |
# Function to query the face generation API | |
def generate_face_image(age, gender): | |
response = requests.post(face_api_url, headers=headers, json={"inputs": f"Photo of {age} years old {gender} with serious face"}) | |
return Image.open(io.BytesIO(response.content)) | |
# Function to generate a random name | |
def generate_random_name(gender): | |
fake = faker.Faker() | |
if gender == "Male": | |
return fake.first_name_male() | |
else: | |
return fake.first_name_female() | |
# Function to generate a random surname | |
def generate_random_surname(): | |
fake = faker.Faker() | |
return fake.last_name() | |
# Function to generate a random birth date | |
def generate_random_birth_date(): | |
fake = faker.Faker() | |
return fake.date_of_birth(minimum_age=18, maximum_age=80).strftime("%m/%d/%Y") | |
# Function to generate a random 6-digit number for fingerprint generation | |
def generate_random_number(): | |
return random.randint(100000, 999999) | |
# Function to query the fingerprint generation API | |
def generate_fingerprint(number): | |
response = requests.post(fingerprint_api_url, headers=headers, json={"inputs": f"Fingerprint of {number}"}) | |
return Image.open(io.BytesIO(response.content)) | |
# Streamlit app layout | |
st.title("Random Data Generator App") | |
st.header("Generate Random Data") | |
# Gender selection input | |
gender = st.selectbox("Select Gender", ["Male", "Female"]) | |
# Generate random name, surname, and birth date | |
name = generate_random_name(gender) | |
surname = generate_random_surname() | |
birth_date = generate_random_birth_date() | |
st.write(f"Name: {name}") | |
st.write(f"Surname: {surname}") | |
st.write(f"Birth Date: {birth_date}") | |
# Calculate age based on birth year | |
birth_year = int(birth_date[-4:]) | |
current_year = datetime.datetime.now().year | |
age = current_year - birth_year | |
st.write(f"Age: {age}") | |
# Generate face image based on age | |
st.write(f"Photo of {age} years old {gender} with serious face:") | |
face_image = generate_face_image(age, gender) | |
st.image(face_image, caption=f"{age} years old {gender}") | |
# Generate random 6-digit number and display fingerprint | |
random_number = generate_random_number() | |
st.write(f"Fingerprint of {random_number}:") | |
fingerprint_image = generate_fingerprint(random_number) | |
st.image(fingerprint_image, caption=f"Fingerprint of {random_number}") | |