Spaces:
Runtime error
Runtime error
Update app.py
Browse files1234567891011123 unmodified lines1617181920212223242526272829303132333435363738396 unmodified lines4647484950import gradio as grfrom transformers import AutoTokenizer, AutoModelForCausalLM, pipelineMODEL_ID = "Chuxia-sys/tiny_model"# Load model & tokenizertokenizer = AutoTokenizer.from_pretrained(MODEL_ID)model = AutoModelForCausalLM.from_pretrained(MODEL_ID)pipe = pipeline("text-generation",model=model,3 unmodified linestop_p=0.9,)SYSTEM_PROMPT = ("You are a helpful AI travel planner specializing only in the Philippines. ""You can recommend itineraries, places, and hotels, but do NOT respond to questions ""outside the Philippines or unrelated to travel.")def chat(user_message, history):# Keep recent contextcontext = ""for turn in history[-3:]: # last 3 exchangescontext += f"[USER] {turn[0]}\n[ASSISTANT] {turn[1]}\n"prompt = f"{SYSTEM_PROMPT}\n{context}[USER] {user_message}\n[ASSISTANT]"output = pipe(prompt)[0]["generated_text"]# Cut off the system prefix if includedresponse = output.split("[ASSISTANT]")[-1].strip()return responsechatbot = gr.ChatInterface(fn=chat,title="π΅π PH Travel Planner Chatbot",6 unmodified linestheme="soft",)if __name__ == "__main__":chatbot.launch()12345678910111213141516173 unmodified lines21222324252627282930313233343536373839404142434445464748496 unmodified lines565758596061import gradio as grfrom transformers import AutoTokenizer, AutoModelForCausalLM, pipeline# === Model Settings ===BASE_MODEL = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"FINETUNED_MODEL = "Chuxia-sys/tiny_model"# β Load tokenizer from base (for compatibility)tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)# β Load fine-tuned modelmodel = AutoModelForCausalLM.from_pretrained(FINETUNED_MODEL)# β Create text generation pipelinepipe = pipeline("text-generation",model=model,3 unmodified linestop_p=0.9,)# === System Prompt ===SYSTEM_PROMPT = ("You are a helpful AI travel planner specializing only in the Philippines. ""You can recommend itineraries, places, and hotels, but do NOT respond to questions ""outside the Philippines or unrelated to travel.")# === Chat Logic ===def chat(user_message, history):# Keep recent contextcontext = ""for turn in history[-3:]: # Keep last 3 user-assistant pairscontext += f"[USER] {turn[0]}\n[ASSISTANT] {turn[1]}\n"prompt = f"{SYSTEM_PROMPT}\n{context}[USER] {user_message}\n[ASSISTANT]"output = pipe(prompt)[0]["generated_text"]# Extract assistant's responseresponse = output.split("[ASSISTANT]")[-1].strip()return response# === Gradio Chat Interface ===chatbot = gr.ChatInterface(fn=chat,title="π΅π PH Travel Planner Chatbot",6 unmodified linestheme="soft",)# === Launch App ===if __name__ == "__main__":chatbot.launch()
app.py+17-6