phi3 / app.py
5urabhi1's picture
Create app.py
a0241db verified
import random
import uuid
import json
from transformers import AutoTokenizer, AutoModelForCausalLM
# Load the tokenizer and model without FlashAttention2
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3.5-vision-instruct")
# Disable FlashAttention2 by forcing default attention
config = {
'attn_implementation': 'default'
}
model = AutoModelForCausalLM.from_pretrained(
"microsoft/Phi-3.5-vision-instruct",
trust_remote_code=True,
**config
)
# Function to generate text using the model
def generate_text(prompt):
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(inputs['input_ids'], max_length=150)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
# Lists for random selection
interest_list = ["networking", "dealMaking"]
personal_interest_list = [
"Drawing", "Cooking", "Foodie", "Board Gaming", "Card games", "Checkers", "Chess",
"PC gaming", "Puzzle solving", "Video gaming", "Reading", "Science experiments",
"Magic and illusion", "Stand-up comedy", "Walking", "Beer brewing", "Gourmet food exploration",
"Mixology", "Wine tasting"
]
professional_interest_list = [
"Building a customer-centric culture", "Community Building", "Community Management",
"Delivering exceptional customer service", "Ensuring product/service quality",
"Handling customer complaints and feedback"
]
# Function to generate random profile with intelligent education/professional details
def generate_intelligent_profile():
# Randomly select interests and location
profile = {
"_id": str(uuid.uuid4()), # Generate random ID
"latitude": random.uniform(-90, 90), # Random latitude
"longitude": random.uniform(-180, 180), # Random longitude
"interest": random.sample(interest_list, random.randint(1, len(interest_list))), # Random interests
"personalInterest": random.sample(personal_interest_list, random.randint(3, 7)), # Random personal interests
"professionalInterest": random.sample(professional_interest_list, random.randint(3, 5)) # Random professional interests
}
# Generate intelligent educational details using the model
education_prompt = "Generate an educational background for a professional profile with relevant qualifications."
profile["educationalDetails"] = [generate_text(education_prompt)]
# Generate intelligent professional details using the model
professional_prompt = "Generate a professional career summary for a profile with achievements and roles."
profile["professionalDetails"] = [generate_text(professional_prompt)]
return profile
# Function to generate multiple profiles
def generate_profiles(num_profiles=5):
profiles = [generate_intelligent_profile() for _ in range(num_profiles)]
return {"data": profiles}
# Generate and print random intelligent profiles
generated_profiles = generate_profiles(3)
print(json.dumps(generated_profiles, indent=4))