Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,39 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import pipeline
|
3 |
|
4 |
-
|
5 |
-
itinerary_generator = pipeline("text-generation", model="rahmanazhar/Travereel-Model-V1")
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
return generated_text.strip()
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
gr.Textbox(label="Your Interests (e.g., beaches, mountains, backwaters, culture)"),
|
19 |
-
gr.Radio(choices=["low", "medium", "high"], label="Budget"),
|
20 |
-
gr.Textbox(label="Specific Places in Kerala (Optional, leave blank for general Kerala trip)")
|
21 |
-
],
|
22 |
-
outputs=gr.Textbox(label="Generated Kerala Trip Plan"),
|
23 |
-
title="Kerala Trip Planner AI",
|
24 |
-
description="Enter your desired trip duration, interests, and budget to get a personalized Kerala itinerary powered by the Travereel model."
|
25 |
-
)
|
26 |
|
27 |
-
#
|
28 |
-
iface.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, pipeline
|
3 |
|
4 |
+
model_name = "rahmanazhar/Travereel-Model-V1"
|
|
|
5 |
|
6 |
+
try:
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
9 |
+
itinerary_generator = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
|
|
|
10 |
|
11 |
+
def generate_kerala_itinerary(duration, interests, budget, specific_places="Kerala"):
|
12 |
+
"""Generates a Kerala trip itinerary based on user inputs."""
|
13 |
+
prompt = f"Generate a {duration}-day trip plan for {specific_places}, Kerala, focusing on {interests} with a {budget} budget."
|
14 |
+
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']
|
15 |
+
return generated_text.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
# Define the input and output interfaces for Gradio
|
18 |
+
iface = gr.Interface(
|
19 |
+
fn=generate_kerala_itinerary,
|
20 |
+
inputs=[
|
21 |
+
gr.Slider(minimum=1, maximum=10, step=1, label="Duration (Days)"),
|
22 |
+
gr.Textbox(label="Your Interests (e.g., beaches, mountains, backwaters, culture)"),
|
23 |
+
gr.Radio(choices=["low", "medium", "high"], label="Budget"),
|
24 |
+
gr.Textbox(label="Specific Places in Kerala (Optional, leave blank for general Kerala trip)")
|
25 |
+
],
|
26 |
+
outputs=gr.Textbox(label="Generated Kerala Trip Plan"),
|
27 |
+
title="Kerala Trip Planner AI",
|
28 |
+
description="Enter your desired trip duration, interests, and budget to get a personalized Kerala itinerary powered by the Travereel model."
|
29 |
+
)
|
30 |
+
|
31 |
+
# Launch the Gradio interface
|
32 |
+
iface.launch()
|
33 |
+
|
34 |
+
except Exception as e:
|
35 |
+
print(f"Error loading model: {e}")
|
36 |
+
def error_message():
|
37 |
+
return f"Error loading the model: {e}. Please check the logs."
|
38 |
+
iface = gr.Interface(fn=error_message, inputs=[], outputs=gr.Textbox(), title="Kerala Trip Planner AI (Error)")
|
39 |
+
iface.launch()
|