Spaces:
Runtime error
Runtime error
Create app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950import gradio as grfrom transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
MODEL_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, tokenizer=tokenizer, max_new_tokens=180, temperature=0.7, top_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 context context = "" for turn in history[-3:]: # last 3 exchanges context += 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 included response = output.split("[ASSISTANT]")[-1].strip() return response
chatbot = gr.ChatInterface( fn=chat, title="🇵🇭 PH Travel Planner Chatbot", description="Ask for travel plans, itineraries, or hotel suggestions anywhere in the Philippines!", examples=[ ["Plan a 3-day trip to Cebu."], ["Suggest some hotels in Palawan near the beach."], ["Where should I go for a weekend in Baguio?"], ], theme="soft",)
if __name__ == "__main__": chatbot.launch()app.pyAdded+50