Spaces:
Sleeping
Sleeping
Ilyas KHIAT
commited on
Commit
·
45479b2
1
Parent(s):
38fc6d8
enhacnemnet
Browse files
data.xlsx
ADDED
|
Binary file (96.7 kB). View file
|
|
|
main.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
from fastapi import FastAPI, HTTPException, UploadFile, File,Request,Depends,status,BackgroundTasks
|
| 2 |
from fastapi.security import OAuth2PasswordBearer
|
| 3 |
from pydantic import BaseModel
|
| 4 |
-
from typing import Optional
|
| 5 |
from uuid import uuid4
|
| 6 |
import os
|
| 7 |
from dotenv import load_dotenv
|
|
@@ -11,6 +11,7 @@ import json
|
|
| 11 |
from prompt import *
|
| 12 |
from fastapi.middleware.cors import CORSMiddleware
|
| 13 |
import requests
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
|
|
@@ -49,7 +50,57 @@ class UserInput(BaseModel):
|
|
| 49 |
stream: Optional[bool] = False
|
| 50 |
messages: Optional[list[dict]] = []
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
#endpoinds
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
@app.post("/generate_sphinx")
|
| 55 |
async def generate_sphinx():
|
|
|
|
| 1 |
from fastapi import FastAPI, HTTPException, UploadFile, File,Request,Depends,status,BackgroundTasks
|
| 2 |
from fastapi.security import OAuth2PasswordBearer
|
| 3 |
from pydantic import BaseModel
|
| 4 |
+
from typing import Optional, List
|
| 5 |
from uuid import uuid4
|
| 6 |
import os
|
| 7 |
from dotenv import load_dotenv
|
|
|
|
| 11 |
from prompt import *
|
| 12 |
from fastapi.middleware.cors import CORSMiddleware
|
| 13 |
import requests
|
| 14 |
+
import pandas as pd
|
| 15 |
|
| 16 |
|
| 17 |
|
|
|
|
| 50 |
stream: Optional[bool] = False
|
| 51 |
messages: Optional[list[dict]] = []
|
| 52 |
|
| 53 |
+
class Artwork(BaseModel):
|
| 54 |
+
name: str
|
| 55 |
+
artist: str
|
| 56 |
+
image_url: str
|
| 57 |
+
date: str
|
| 58 |
+
description: str
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
# Global variable to store the data
|
| 62 |
+
artworks_data = []
|
| 63 |
+
|
| 64 |
+
def load_data():
|
| 65 |
+
global artworks_data
|
| 66 |
+
|
| 67 |
+
# Provide the path to your local spreadsheet
|
| 68 |
+
spreadsheet_path = "data.xlsx"
|
| 69 |
+
|
| 70 |
+
# Read the spreadsheet into a DataFrame
|
| 71 |
+
df = pd.read_excel(spreadsheet_path, sheet_name='Sheet1') # Adjust sheet_name as needed
|
| 72 |
+
|
| 73 |
+
df = df.fillna(False)
|
| 74 |
+
# Convert DataFrame to a list of dictionaries
|
| 75 |
+
df_filtered = df[df['Publication'] == True]
|
| 76 |
+
|
| 77 |
+
artworks_data = df_filtered.to_dict(orient='records')
|
| 78 |
+
|
| 79 |
+
print("Data loaded successfully")
|
| 80 |
+
|
| 81 |
+
load_data()
|
| 82 |
+
|
| 83 |
#endpoinds
|
| 84 |
+
@app.get("/artworks/{artist_name}")
|
| 85 |
+
async def get_artworks_by_artist(artist_name: str):
|
| 86 |
+
artist_name_lower = artist_name.lower()
|
| 87 |
+
results = []
|
| 88 |
+
|
| 89 |
+
for artwork in artworks_data:
|
| 90 |
+
if artist_name_lower in artwork['Artiste'].lower():
|
| 91 |
+
result = {
|
| 92 |
+
'name':artwork['Titre français'],
|
| 93 |
+
'artist':artwork['Artiste'],
|
| 94 |
+
'image_url':artwork['Image_URL'],
|
| 95 |
+
'date':str(artwork['Date']), # Ensure date is a string
|
| 96 |
+
'description':artwork['Media']
|
| 97 |
+
}
|
| 98 |
+
results.append(result)
|
| 99 |
+
|
| 100 |
+
if not results:
|
| 101 |
+
raise HTTPException(status_code=404, detail="Artist not found")
|
| 102 |
+
|
| 103 |
+
return results
|
| 104 |
|
| 105 |
@app.post("/generate_sphinx")
|
| 106 |
async def generate_sphinx():
|