Update app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445import gradio as grfrom transformers import pipelineimport requests# Load both the standard and premium modelsstandard_model = pipeline("conversational", model="microsoft/DialoGPT-medium")premium_model = pipeline("conversational", model="microsoft/DialoGPT-large")# Your Boosty API key or any method of checking subscriptionsBOOSTY_API_KEY = "YOUR_BOOSTY_API_KEY"BOOSTY_API_URL = "https://boosty.to/api/subscription_check" # Replace with the actual Boosty API URL# Function to check if a user is a premium member on Boostydef is_premium_user(boosty_user_id: str) -> bool:response = requests.get(f"{BOOSTY_API_URL}?user_id={boosty_user_id}", headers={"Authorization": f"Bearer {BOOSTY_API_KEY}"})if response.status_code != 200:return False # Assuming non-200 response means not premium# Assuming the response contains a field like 'is_premium': True/Falsereturn response.json().get("is_premium", False)# Chat function to use the correct model based on Boosty subscriptiondef chat_with_ai(user_input, boosty_user_id):# Check if the user is a premium memberif is_premium_user(boosty_user_id):model_to_use = premium_modelelse:model_to_use = standard_model# Get AI responseconversation = model_to_use(user_input)return conversation[-1]["generated_text"]# Create the Gradio interfaceiface = gr.Interface(fn=chat_with_ai,inputs=["text", gr.Textbox(label="Boosty User ID")],outputs="text",live=True,title="AI Chatbot")# Launch the Gradio app as an APIiface.launch(server_name="0.0.0.0", server_port=7860, share=True)123456789101112131415161718192021222324252627282930313233343536373839404142434445import gradio as grfrom transformers import pipelineimport requests# Load both the standard and premium modelsstandard_model = pipeline("conversational", model="google/mt5-base")premium_model = pipeline("conversational", model="google/mt5-base")# Your Boosty API key or any method of checking subscriptionsBOOSTY_API_KEY = "YOUR_BOOSTY_API_KEY"BOOSTY_API_URL = "https://boosty.to/api/subscription_check" # Replace with the actual Boosty API URL# Function to check if a user is a premium member on Boostydef is_premium_user(boosty_user_id: str) -> bool:response = requests.get(f"{BOOSTY_API_URL}?user_id={boosty_user_id}", headers={"Authorization": f"Bearer {BOOSTY_API_KEY}"})if response.status_code != 200:return False # Assuming non-200 response means not premium# Assuming the response contains a field like 'is_premium': True/Falsereturn response.json().get("is_premium", False)# Chat function to use the correct model based on Boosty subscriptiondef chat_with_ai(user_input, boosty_user_id):# Check if the user is a premium memberif is_premium_user(boosty_user_id):model_to_use = premium_modelelse:model_to_use = standard_model# Get AI responseconversation = model_to_use(user_input)return conversation[-1]["generated_text"]# Create the Gradio interfaceiface = gr.Interface(fn=chat_with_ai,inputs=["text", gr.Textbox(label="Boosty User ID")],outputs="text",live=True,title="AI Chatbot")# Launch the Gradio app as an APIiface.launch(server_name="0.0.0.0", server_port=7860, share=True)
app.py+45-45