Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,31 +7,43 @@ dataset = load_dataset("huggan/wikiart", streaming=True)
|
|
7 |
|
8 |
# Function to display artwork details
|
9 |
def display_artwork(index):
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
13 |
|
14 |
# Function to filter artworks based on metadata
|
15 |
def filter_artworks(artist=None, genre=None, style=None):
|
16 |
results = []
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
22 |
return results
|
23 |
|
24 |
# Function to display filtered artworks
|
25 |
def display_filtered_artworks(artist, genre, style):
|
26 |
filtered_results = filter_artworks(artist, genre, style)
|
|
|
|
|
27 |
return [(r["image"], f"Title: {r['title']}\nArtist: {r['artist']}\nStyle: {r['style']}\nGenre: {r['genre']}") for r in filtered_results]
|
28 |
|
29 |
# Chatbot functionality for museum guide persona using a publicly available Hugging Face model
|
30 |
chatbot = pipeline("text-generation", model="gpt2") # Replace with a valid Hugging Face model
|
31 |
|
32 |
def museum_guide_query(prompt):
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
35 |
|
36 |
# Gradio interfaces
|
37 |
artwork_interface = gr.Interface(
|
|
|
7 |
|
8 |
# Function to display artwork details
|
9 |
def display_artwork(index):
|
10 |
+
try:
|
11 |
+
for i, record in enumerate(dataset["train"]): # Stream through the dataset
|
12 |
+
if i == index:
|
13 |
+
return record["image"], f"Title: {record['title']}\nArtist: {record['artist']}\nStyle: {record['style']}\nGenre: {record['genre']}"
|
14 |
+
return None, "Error: Index out of range or invalid."
|
15 |
+
except Exception as e:
|
16 |
+
return None, f"Error: {str(e)}"
|
17 |
|
18 |
# Function to filter artworks based on metadata
|
19 |
def filter_artworks(artist=None, genre=None, style=None):
|
20 |
results = []
|
21 |
+
try:
|
22 |
+
for record in dataset["train"]:
|
23 |
+
if (artist is None or record["artist"] == artist) and \
|
24 |
+
(genre is None or record["genre"] == genre) and \
|
25 |
+
(style is None or record["style"] == style):
|
26 |
+
results.append(record)
|
27 |
+
except Exception as e:
|
28 |
+
return []
|
29 |
return results
|
30 |
|
31 |
# Function to display filtered artworks
|
32 |
def display_filtered_artworks(artist, genre, style):
|
33 |
filtered_results = filter_artworks(artist, genre, style)
|
34 |
+
if len(filtered_results) == 0:
|
35 |
+
return None, "No artworks found with the specified filters."
|
36 |
return [(r["image"], f"Title: {r['title']}\nArtist: {r['artist']}\nStyle: {r['style']}\nGenre: {r['genre']}") for r in filtered_results]
|
37 |
|
38 |
# Chatbot functionality for museum guide persona using a publicly available Hugging Face model
|
39 |
chatbot = pipeline("text-generation", model="gpt2") # Replace with a valid Hugging Face model
|
40 |
|
41 |
def museum_guide_query(prompt):
|
42 |
+
try:
|
43 |
+
response = chatbot(prompt, max_length=100, num_return_sequences=1)
|
44 |
+
return response[0]["generated_text"]
|
45 |
+
except Exception as e:
|
46 |
+
return f"Error: {str(e)}"
|
47 |
|
48 |
# Gradio interfaces
|
49 |
artwork_interface = gr.Interface(
|