File size: 3,125 Bytes
8ec7b05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f886efc
 
 
70af6e4
f886efc
 
 
8ec7b05
f886efc
 
 
 
 
 
 
 
 
8ec7b05
 
 
 
 
 
 
 
 
aed02f5
8ec7b05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# app.py

import gradio as gr
import pandas as pd
from PIL import Image
import io
import requests
import base64


def process_excel(file):
    # Check if the file is None
    if file is None:
        return "No file uploaded.", pd.DataFrame()

    # Read the uploaded Excel file into a DataFrame
    try:
        df = pd.read_excel(file.name, engine='openpyxl')
    except Exception as e:
        return f"Error reading Excel file: {str(e)}", pd.DataFrame()

    # Extract card information
    cards = []
    for index, row in df.iterrows():
        if row['์‚ฌ์šฉ์—ฌ๋ถ€'] != 'Y':
            continue
        
        image_url = row['์‚ฌ์ง„']
        try:
            response = requests.get(image_url)
            response.raise_for_status()  # Ensure we notice bad responses

            # Validate if the response contains image data
            if 'image' not in response.headers.get('Content-Type', ''):
                raise ValueError("URL does not point to an image")

            image = Image.open(io.BytesIO(response.content))

            with io.BytesIO() as output:
                image.save(output, format="PNG")
                image_data = base64.b64encode(output.getvalue()).decode('utf-8')

        except Exception as e:
            print(f"Error processing image from URL {image_url}: {str(e)}")
            image_data = None

        # Create card layout
        card = f"""
        <div style="width: 800px; height: 400px; border: 1px solid #333; margin: 10px auto; background-color: #2E6A8C; color: white; font-family: Arial, sans-serif; display: flex; flex-direction: row;">
            <div style="text-align: center; padding: 10px; font-size: 18px; border-bottom: 1px solid white;">
                {row['์ œํ’ˆ๋ช…']} / {row['ํŒ๋งค์›']}
            </div>
            <div></div>
            <div style="display: flex; flex-direction: col;">
                <img src="data:image/png;base64,{image_data}" alt="Image" style="max-width: 50%; max-height: 100%; object-fit: cover; border-right: 1px solid white;">            
                <div style="flex; text-align: center; padding: 10px;">
                    <div style="margin-bottom: 10px;">์ฃผ์„ฑ๋ถ„: {row['์ฃผ์š”์„ฑ๋ถ„']}</div>
                    <div style="margin-bottom: 10px;">1ํšŒ ์šฉ๋Ÿ‰: {row['1ํšŒ ์šฉ๋Ÿ‰']}</div>
                    <div style="margin-bottom: 10px;">1์ผ ๋ณต์šฉ ํšŸ์ˆ˜: {row['1์ผ ๋ณต์šฉํšŸ์ˆ˜']}</div>
                    <div>๊ทœ๊ฒฉ: {row['๊ทœ๊ฒฉ']}</div>
                </div> 
            </div>            
        </div>
        """
        cards.append(card)
    
    return df, "\n\n".join(cards)

iface = gr.Interface(
    fn=process_excel,
    inputs=gr.File(type="filepath", label="excel ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•ด์ฃผ์„ธ์š”."),
    outputs=[gr.Dataframe(label="์ž…๋ ฅ๊ฐ’"), gr.HTML(label="๋ธŒ๋กœ์…”")],
    live=True
)

iface.launch()


iface = gr.Interface(
    fn=process_excel,
    inputs=gr.File(type="filepath", label="excel ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•ด์ฃผ์„ธ์š”."),
    # outputs=gr.Markdown(),
    outputs=[gr.Dataframe(label="์ž…๋ ฅ๊ฐ’"), gr.HTML(label="๋ธŒ๋กœ์…”")],
    live=True
)

iface.launch()