Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from groq import Groq
|
| 4 |
+
|
| 5 |
+
# Load API key securely
|
| 6 |
+
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
| 7 |
+
client = Groq(api_key=GROQ_API_KEY)
|
| 8 |
+
|
| 9 |
+
def generate_itinerary(mood, location, budget, days):
|
| 10 |
+
prompt = f"Create a {days}-day travel itinerary to {location}. The mood of the traveler is {mood} and the budget is {budget}."
|
| 11 |
+
completion = client.chat.completions.create(
|
| 12 |
+
model="gemma2-9b-it",
|
| 13 |
+
messages=[
|
| 14 |
+
{"role": "system", "content": "You are an expert travel planner."},
|
| 15 |
+
{"role": "user", "content": prompt}
|
| 16 |
+
],
|
| 17 |
+
temperature=1,
|
| 18 |
+
max_completion_tokens=1024,
|
| 19 |
+
top_p=1,
|
| 20 |
+
stream=False
|
| 21 |
+
)
|
| 22 |
+
return completion.choices[0].message.content
|
| 23 |
+
|
| 24 |
+
with gr.Blocks() as demo:
|
| 25 |
+
gr.Markdown("# Mood-based Travel Itinerary Planner")
|
| 26 |
+
|
| 27 |
+
with gr.Row():
|
| 28 |
+
mood = gr.Dropdown(
|
| 29 |
+
["Adventure", "Relaxing", "Romantic", "Cultural"],
|
| 30 |
+
label="Mood"
|
| 31 |
+
)
|
| 32 |
+
location = gr.Textbox(label="Destination", placeholder="e.g., India, Japan, France")
|
| 33 |
+
|
| 34 |
+
with gr.Row():
|
| 35 |
+
budget = gr.Dropdown(["Low", "Medium", "High"], label="Budget")
|
| 36 |
+
days = gr.Number(value=5, precision=0, label="Days")
|
| 37 |
+
|
| 38 |
+
output = gr.Textbox(label="Generated Itinerary", lines=20)
|
| 39 |
+
btn = gr.Button("Generate Itinerary")
|
| 40 |
+
btn.click(generate_itinerary, inputs=[mood, location, budget, days], outputs=output)
|
| 41 |
+
|
| 42 |
+
demo.launch()
|