Views
No views yet
Llama-3.1 designed to assist tourists in Morocco by providing recommendations for hotels, beaches, restaurants, and activities based on user queries.1!pip install gradio
2import gradio as gr
3from transformers import AutoModelForCausalLM, AutoTokenizer
4
5model = AutoModelForCausalLM.from_pretrained("aboutaleb/llama-3-8b-chat-tourismneweeest")
6tokenizer = AutoTokenizer.from_pretrained("aboutaleb/llama-3-8b-chat-tourismneweeest")
7
8def get_recommendations(user_query):
9 """
10 Function to generate tourism recommendations based on user input.
11 """
12 # Preprocessing: remove unwanted characters (e.g., </)
13 cleaned_query = user_query.replace('</', '').replace('>', '')
14
15 # Format input text with instructions
16 input_text = f"""Below is a user query about tourism in Morocco. Provide concise and accurate recommendations:
17
18### User Query:
19{cleaned_query}
20### Recommendations:
21"""
22 # Tokenization and generation
23 inputs = tokenizer([input_text], return_tensors="pt", truncation=True).to("cuda")
24 outputs = model.generate(**inputs, max_new_tokens=100)
25
26 # Decode the response and clean unnecessary tags
27 recommendations = tokenizer.decode(outputs[0], skip_special_tokens=True)
28
29 # Clean additional tokens (</s> or others)
30 recommendations = recommendations.replace('</s>', '').strip()
31
32 # Return only the recommendations section
33 if "### Recommendations:" in recommendations:
34 recommendations = recommendations.split("### Recommendations:")[1].strip()
35
36 return recommendations
37
38# Gradio Interface
39with gr.Blocks() as demo:
40 gr.Markdown("## Moroccan Tourism Assistant")
41 gr.Markdown(
42 "Enter your query about tourism in Morocco below. "
43 "You will receive recommendations for hotels, beaches, restaurants, or activities."
44 )
45
46 with gr.Row():
47 input_box = gr.Textbox(
48 label="User Query",
49 placeholder="Enter your question about tourism in Morocco here...",
50 lines=5
51 )
52 output_box = gr.Textbox(
53 label="Generated Recommendations",
54 placeholder="Recommendations will appear here...",
55 lines=5
56 )
57
58 generate_button = gr.Button("Get Recommendations")
59 generate_button.click(get_recommendations, inputs=input_box, outputs=output_box)
60
61# Launch the application
62demo.launch()