Spaces:
Sleeping
Sleeping
Panagiotis Spanakis commited on
Commit ·
ba767c7
1
Parent(s): 8bd9f17
Init
Browse files- app.py +68 -0
- requirements.txt +7 -0
app.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
from huggingface_hub import InferenceClient
|
| 4 |
+
|
| 5 |
+
# Initialize Mistral client
|
| 6 |
+
client = InferenceClient(token=os.environ.get("HF_TOKEN"))
|
| 7 |
+
|
| 8 |
+
def glyfada_chat(message, history):
|
| 9 |
+
# Check if question is about Glyfada/Athens
|
| 10 |
+
message_lower = message.lower()
|
| 11 |
+
glyfada_keywords = ["glyfada", "athens", "greece", "beach", "restaurant", "food",
|
| 12 |
+
"shopping", "transport", "hotel", "activities", "where", "how", "what"]
|
| 13 |
+
|
| 14 |
+
if not any(word in message_lower for word in glyfada_keywords):
|
| 15 |
+
return "I'm your Glyfada guide! 🏖️ Ask me about beaches, restaurants, shopping, or activities in Glyfada, Athens!"
|
| 16 |
+
|
| 17 |
+
# Create system prompt for Mistral
|
| 18 |
+
system_prompt = """You are a helpful local guide for Glyfada, Athens, Greece.
|
| 19 |
+
|
| 20 |
+
ONLY answer questions about Glyfada, Athens, or tourism in Greece.
|
| 21 |
+
|
| 22 |
+
Provide helpful information about:
|
| 23 |
+
- Beaches (Glyfada Beach, Asteria, Balux)
|
| 24 |
+
- Restaurants and tavernas
|
| 25 |
+
- Shopping (Avenue Mall, Marina Flisvos)
|
| 26 |
+
- Transportation (tram, buses)
|
| 27 |
+
- Activities (golf, water sports, marina walks)
|
| 28 |
+
|
| 29 |
+
Be friendly like a local Greek guide. Keep responses under 150 words."""
|
| 30 |
+
|
| 31 |
+
# Prepare messages for Mistral
|
| 32 |
+
messages = [{"role": "system", "content": system_prompt}]
|
| 33 |
+
|
| 34 |
+
# Add history
|
| 35 |
+
for msg in history:
|
| 36 |
+
messages.append({"role": msg["role"], "content": msg["content"]})
|
| 37 |
+
|
| 38 |
+
# Add current message
|
| 39 |
+
messages.append({"role": "user", "content": message})
|
| 40 |
+
|
| 41 |
+
try:
|
| 42 |
+
# Call Mistral via HuggingFace
|
| 43 |
+
response = client.chat.completions.create(
|
| 44 |
+
model="mistralai/Mistral-7B-Instruct-v0.3",
|
| 45 |
+
messages=messages,
|
| 46 |
+
max_tokens=200,
|
| 47 |
+
temperature=0.7
|
| 48 |
+
)
|
| 49 |
+
return response.choices[0].message.content
|
| 50 |
+
|
| 51 |
+
except Exception as e:
|
| 52 |
+
return f"Sorry, I'm having trouble right now. Please ask me about Glyfada beaches, restaurants, or activities! Error: {str(e)}"
|
| 53 |
+
|
| 54 |
+
# Create the ChatInterface
|
| 55 |
+
demo = gr.ChatInterface(
|
| 56 |
+
fn=glyfada_chat,
|
| 57 |
+
type="messages",
|
| 58 |
+
title="🏖️ Glyfada Athens Guide",
|
| 59 |
+
description="Your local assistant for exploring Glyfada and the Athens Riviera!",
|
| 60 |
+
examples=[
|
| 61 |
+
"What are the best beaches in Glyfada?",
|
| 62 |
+
"Where should I eat in Glyfada?",
|
| 63 |
+
"How do I get to Glyfada from Athens?",
|
| 64 |
+
"What activities can I do in Glyfada?"
|
| 65 |
+
]
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=5.0.0
|
| 2 |
+
transformers>=4.35.0
|
| 3 |
+
torch>=2.0.0
|
| 4 |
+
huggingface_hub>=0.28.1
|
| 5 |
+
tokenizers>=0.15.0
|
| 6 |
+
accelerate>=0.25.0
|
| 7 |
+
safetensors>=0.4.0
|