Spaces:
No application file
No application file
# -*- coding: utf-8 -*- | |
"""Travel_AI_Guide | |
Automatically generated by Colab. | |
Original file is located at | |
https://colab.research.google.com/drive/1oOV3Nbtygx8NjIUKyhzvc5pjyjSO2HMj | |
""" | |
!pip install gradio Pillow | |
import gradio as gr | |
import requests | |
from PIL import Image | |
import io | |
# Function to query the travel tips model for Japan | |
def query_travel_tips(destination): | |
API_URL = "https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-Instruct-v0.1" | |
HEADERS = {"Authorization": "Bearer HF_TOKEN"} | |
payload = {"inputs": f"I'm planning a trip to {destination}. Can you provide some travel tips?"} | |
response = requests.post(API_URL, headers=HEADERS, json=payload) | |
if response.status_code == 200: | |
return response.json()[0]['generated_text'] | |
else: | |
return "Sorry, I couldn't generate travel tips for Japan." | |
# Function to query the image generation model based on Japan | |
def query_image_generation(text): | |
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0" | |
headers = {"Authorization": "Bearer HF_TOKEN"} | |
response = requests.post(API_URL, headers=headers, json={"inputs": text}) | |
if response.status_code == 200: | |
image_bytes = response.content | |
# Open the image using PIL from the image bytes | |
image = Image.open(io.BytesIO(image_bytes)) | |
return image | |
else: | |
return None | |
# Define the Gradio interface | |
def travel_planner(destination, query): | |
# Query travel tips model | |
travel_tips = query_travel_tips(destination) | |
# Query image generation model | |
image = query_image_generation(query) | |
return travel_tips, image | |
# Create the Gradio interface with customized style | |
iface = gr.Interface( | |
fn=travel_planner, | |
inputs=["text", "text"], | |
outputs=["text", "image"], | |
title="Travel Planner AI", | |
description="Enter your destination and a query related to Japan to get travel tips and an image.", | |
allow_flagging=False, | |
theme="compact", | |
css=""" | |
.gr-input textarea, .gr-output textarea { | |
background-color: white !important; | |
color: black !important; | |
} | |
.gr-body { | |
background-color: #FFC0CB; /* Cherry blossom pink */ | |
} | |
""" | |
) | |
# Launch the interface | |
iface.launch() | |
import os | |
# Change directory to the desired location | |
os.chdir("/content/drive/MyDrive/GenAi/SEE Project/Final") | |
# Now you are in the desired directory | |
!gradio deploy |