File size: 1,953 Bytes
9130059
0c546ad
9130059
0c546ad
9130059
0c546ad
 
 
 
9130059
0c546ad
 
 
 
 
9130059
0c546ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import gradio as gr
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, pipeline

model_name = "rahmanazhar/Travereel-Model-V1"

try:
    tokenizer = AutoTokenizer.from_pretrained(model_name)
    model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
    itinerary_generator = pipeline("text2text-generation", model=model, tokenizer=tokenizer)

    def generate_kerala_itinerary(duration, interests, budget, specific_places="Kerala"):
        """Generates a Kerala trip itinerary based on user inputs."""
        prompt = f"Generate a {duration}-day trip plan for {specific_places}, Kerala, focusing on {interests} with a {budget} budget."
        generated_text = itinerary_generator(prompt, max_length=500, num_return_sequences=1, do_sample=True, top_k=50, top_p=0.95)[0]['generated_text']
        return generated_text.strip()

    # Define the input and output interfaces for Gradio
    iface = gr.Interface(
        fn=generate_kerala_itinerary,
        inputs=[
            gr.Slider(minimum=1, maximum=10, step=1, label="Duration (Days)"),
            gr.Textbox(label="Your Interests (e.g., beaches, mountains, backwaters, culture)"),
            gr.Radio(choices=["low", "medium", "high"], label="Budget"),
            gr.Textbox(label="Specific Places in Kerala (Optional, leave blank for general Kerala trip)")
        ],
        outputs=gr.Textbox(label="Generated Kerala Trip Plan"),
        title="Kerala Trip Planner AI",
        description="Enter your desired trip duration, interests, and budget to get a personalized Kerala itinerary powered by the Travereel model."
    )

    # Launch the Gradio interface
    iface.launch()

except Exception as e:
    print(f"Error loading model: {e}")
    def error_message():
        return f"Error loading the model: {e}. Please check the logs."
    iface = gr.Interface(fn=error_message, inputs=[], outputs=gr.Textbox(), title="Kerala Trip Planner AI (Error)")
    iface.launch()