Update app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445import gradio as grfrom transformers import pipelineimport requests# Use the text-generation taskstandard_model = pipeline("text-generation", model="google/mt5-base")premium_model = pipeline("text-generation", 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[0]["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)12345678910111213141516171819import gradio as grfrom transformers import T5Tokenizer, T5ForConditionalGeneration, pipeline# Load the model and tokenizertokenizer = T5Tokenizer.from_pretrained("google/mt5-base")model = T5ForConditionalGeneration.from_pretrained("google/mt5-base")# Set up the Gradio interface for text generationdef generate_text(prompt):# Use the tokenizer and model to generate textinputs = tokenizer(prompt, return_tensors="pt")outputs = model.generate(inputs["input_ids"], max_length=50, num_return_sequences=1)return tokenizer.decode(outputs[0], skip_special_tokens=True)# Create a Gradio interfaceinterface = gr.Interface(fn=generate_text, inputs="text", outputs="text")# Launch the interfaceinterface.launch()
app.py+14-40