Spaces:
Sleeping
Sleeping
File size: 8,817 Bytes
50a3b6b a650127 b6ffccd 803cafa fc1a8c9 d3daf89 3b3441d 846f381 2f76041 fc1a8c9 00b8164 fc1a8c9 846f381 96757e9 2f6326c 96757e9 50a3b6b 96757e9 70af3e6 43125b5 96757e9 43125b5 96757e9 f7f8f39 803cafa 846f381 f7f8f39 2f6326c 96757e9 108ee43 803cafa 70af3e6 803cafa 96757e9 bbd22f1 662b783 f2110a9 3a88230 f2110a9 2f6326c 2f76041 662b783 475d4cc f7f8f39 662b783 bbd22f1 2f6326c bbd22f1 803cafa bbd22f1 32d408d 844a2ad 2f6326c 475d4cc 2f6326c 475d4cc f2110a9 2f6326c 12d4b1f 37479ea a25423a 846f381 803cafa 7fe40bc 803cafa 32d408d 803cafa 70af3e6 32d408d 803cafa 4189ddb 96757e9 803cafa 07f4c4c 2a6afc2 803cafa |
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
import gradio as gr
import os
import requests
import dateparser
from datasets import load_dataset
from datetime import datetime, timedelta
from sentence_transformers import SentenceTransformer
from huggingface_hub import InferenceClient
file_path = 'requirements.txt'
dataset = load_dataset("text", data_files = "requirements.txt")
with open("requirements.txt", "r", encoding = "utf-8") as file:
file_path = file.read()
print(file_path)
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
def match_europe(scores):
a = scores.count("A")
b = scores.count("B")
c = scores.count("C")
d = scores.count("D")
e = scores.count("E")
if a >= 5:
return "Paris, France"
elif b >=5:
return "Tokyo, Japan"
elif c >= 5:
return "Bali, Indonesia"
elif d >= 5:
return "New York City, USA"
elif e >=5:
return "Barcelona, Spain"
else:
if a > b and a > c and a > d and a > e:
return "Paris, France"
elif b > a and b > c and b > d and b > e:
return "Tokyo, Japan"
elif c > a and c > b and c > d and c > e:
return "Bali, Indonesia"
elif d > a and d > b and d > c and d > e:
return "New York City, USA"
elif e > a and e > b and e > c and e > d:
return "Barcelona, Spain"
else:
return "Sydney, Australia"
questions_europe = [
("1. What kind of people do you enjoy meeting?", [
("A", "Locals who know the city's deep history and culture."),
("B", "Curious travelers and polite locals with cool stories."),
("C", "Easygoing, spiritual people who live simply."),
("D", "Bold, confident people chasing big dreams."),
("E", "Social butterflies who love music and street life.")
]),
("2. What type of souvenir do you want to bring home?", [
("A", "A vintage print from a street artist."),
("B", "A quirky gadget or handmade oragami."),
("C", "A handmade bracelet and beach sarong."),
("D", "A t-shirt from a local streetwear brand."),
("E", "A flamenco fan or mosaic-tiled trinket.")
]),
("3. Choose an activity for your ideal day.", [
("A", "Browsing a weekend market,then sipping espresso at a corner café."),
("B", "Eating noodles in a hidden alley, then watching a city sunset from a rooftop temple."),
("C", "Surfing, spa treatments, or a sunrise hike."),
("D", "Exploring thrift shops, then catching a pop-up art show downtown."),
("E", "Dancing on the beach and exploring local street art.")
]),
("4. What kind of weather do you prefer?", [
("A", "Mild and breezy with lots of sunshine."),
("B", "Cool evenings and warm days."),
("C", "Hot and tropical with ocean breezes."),
("D", "Crisp air with clear skies."),
("E", "Warm with a chance of an evening breeze.")
]),
("5. You stumble upon a secret cafe. What do you order?", [
("A", "A delicate pastry no one else seems to know about."),
("B", "A spicy noodle dish served with an unusual garnish."),
("C", "A refreshing tropical drink with exotic fruits."),
("D", "A hearty bagel sandwich perfect for people on the go."),
("E", "A colorful shaved ice dessert topped with unexpected flavors.")
])
]
def create_quiz(questions, match_func):
with gr.Blocks(css = "#rounded-btn {border-radius: 12px; padding: 10px 20px}")as demo:
answers = []
with gr.Column():
for q, opts in questions:
choices = [opt[1] for opt in opts]
answers.append(gr.Radio(choices=choices, label=q))
result = gr.Textbox(label="You should travel to...")
btn = gr.Button("Find Ideal Location", elem_id = "rounded-btn")
def evaluate(*vals):
codes = []
for i, val in enumerate(vals):
if val is None:
codes.append("C")
else:
codes.append(next(opt[0] for opt in questions[i][1] if opt[1] == val))
return match_func(codes)
btn.click(evaluate, inputs=answers, outputs=result)
return answers, result, btn
with gr.Blocks() as demo:
gr.Markdown("Quiz")
with gr.Tabs():
with gr.TabItem("Quiz"):
create_quiz(questions_europe, match_europe)
travel_guide_output = ""
def parse_date(date_str):
if not date_str:
return None
parsed_date = dateparser.parse(date_str, settings={'PREFER_DATES_FROM': 'future'})
return parsed_date if parsed_date else None
def respond(destination, transportation, date, preference, include_options, minors):
global travel_guide_output
travel_date = parse_date(date)
prompt = f"""
**Travel Plan Details:**
- **To:** {destination}
- **Transportation:** {transportation}
- **Travel Date:** {date}
- **Budget Preference:** {preference}
- **Minors included:** {minors}
- **Additional Info:** {', '.join(include_options) if include_options else 'None'}
"""
travel_guide_output = prompt
print("respond", travel_guide_output)
return prompt
# try:
# response = client.chat_completion(messages=[{"role": "user", "content": prompt}])
# print(response)
# travel_guide_output = response
# print(travel_guide_output)
# return response['choices'][0]['message']['content'].strip()
# except Exception as e:
# return f"An error occurred: {e}"
def chatbot_respond(message, chat_history):
global travel_guide_output
print("chatbot_respond", travel_guide_output)
if not travel_guide_output:
travel_guide_output = "No travel guide has been generated yet. Please enter your travel details first."
system_message = f"""
You are a chatbot that helps people plan trips. Use the following details to assist them: {travel_guide_output}
Based on how long they are going on their trip, give a day by day explanation, including budget as well using the details provided.
Bold important information for it to be easy on the users eyes.
"""
messages = []
messages.append({"role": "system", "content": system_message})
if chat_history:
messages.extend(chat_history)
try:
response = client.chat_completion(messages)
return response['choices'][0]['message']['content'].strip()
except Exception as e:
return f"An error occurred: {e}"
with gr.Blocks(theme='shivi/calm_seafoam') as app:
gr.Markdown("# 🌍 Travia")
gr.Markdown("Welcome to Travia! We are here to help you plan your trip so that you can enjoy a vacation stress-free!")
with gr.Tabs():
with gr.TabItem("Quiz"):
create_quiz(questions_europe, match_europe)
with gr.TabItem("Travel Chatbot"):
with gr.Row():
with gr.Column(scale=1):
destination_input = gr.Textbox(label="Travel Destination")
transportation_dropdown = gr.Dropdown(["Bus", "Plane", "Train"], label="Preferred Transportation")
date_input = gr.Textbox(label="Travel Duration (e.g. 1 week)")
preference_dropdown = gr.Dropdown(["Luxurious", "Cheap", "Balanced"], label="Budget Preferences")
minors_included = gr.Dropdown(["Yes", "No"], label="Are there minors on the trip?")
include_checkboxes = gr.CheckboxGroup([
"Hotels", "Nearby Attractions", "Basic Phrases in the Language", "Popular Foods"], label="Include in Chat")
send_button = gr.Button("Generate Guide")
with gr.Column(scale=2):
output_box = gr.Markdown(label="AI Output", value="Please enter your travel details and click 'Generate Guide'.")
with gr.Column(scale=1):
gr.ChatInterface(
chatbot_respond,
type="messages",
title="Travia",
examples=[
"I would like to travel to a place, but I don't know how to plan it",
"I need to budget for my trip.",
"I want to learn more about the language, food, and culture of the place I'm traveling to."
])
send_button.click(
respond,
inputs=[destination_input, transportation_dropdown, date_input, preference_dropdown, include_checkboxes, minors_included],
outputs=[output_box]
)
app.launch(debug = True) |