hasune
Initial commit
559023d
raw
history blame
7.79 kB
import gradio as gr
import json
import os
from datetime import datetime
def extract_model_info(config_file):
"""config.json ํŒŒ์ผ์—์„œ ๋ชจ๋ธ ์ •๋ณด ์ถ”์ถœ"""
try:
if config_file is None:
return None
# ํŒŒ์ผ ์ฝ๊ธฐ
config_content = config_file.read().decode('utf-8')
config = json.loads(config_content)
# ์ฃผ์š” ์ •๋ณด ์ถ”์ถœ
model_info = {
'architecture': config.get('model_type', 'Unknown'),
'hidden_size': config.get('hidden_size', 'Unknown'),
'num_layers': config.get('num_hidden_layers', config.get('num_layers', 'Unknown')),
'num_attention_heads': config.get('num_attention_heads', 'Unknown'),
'vocab_size': config.get('vocab_size', 'Unknown'),
'max_position_embeddings': config.get('max_position_embeddings', 'Unknown')
}
return model_info
except Exception as e:
return f"Error parsing config: {str(e)}"
def generate_model_card(config_file, model_name, short_description, model_description, dataset_name, task_type, language, license_type):
"""๋ชจ๋ธ ์นด๋“œ ์ž๋™ ์ƒ์„ฑ"""
# ๊ธฐ๋ณธ ์ •๋ณด ์„ค์ •
if not model_name:
model_name = "My Model"
if not short_description:
short_description = "A fine-tuned model"
if not model_description:
model_description = "A fine-tuned model for specific tasks"
if not dataset_name:
dataset_name = "Custom dataset"
if not task_type:
task_type = "Text classification"
if not language:
language = "Korean"
if not license_type:
license_type = "apache-2.0"
# ๋ชจ๋ธ ์ •๋ณด ์ถ”์ถœ
model_info = extract_model_info(config_file) if config_file else None
# ๋ชจ๋ธ ์นด๋“œ ํ…œํ”Œ๋ฆฟ
model_card = f"""---
license: {license_type}
language: {language.lower()}
pipeline_tag: text-classification
tags:
- {task_type.lower().replace(' ', '-')}
- {language.lower()}
base_model: ""
datasets:
- {dataset_name.lower().replace(' ', '-')}
---
# {model_name}
{short_description}
## Model Description
{model_description}
## Model Details
"""
# ๋ชจ๋ธ ์ •๋ณด๊ฐ€ ์žˆ์œผ๋ฉด ์ถ”๊ฐ€
if model_info and isinstance(model_info, dict):
model_card += f"""- **Architecture**: {model_info['architecture']}
- **Hidden Size**: {model_info['hidden_size']}
- **Number of Layers**: {model_info['num_layers']}
- **Attention Heads**: {model_info['num_attention_heads']}
- **Vocabulary Size**: {model_info['vocab_size']}
- **Max Position Embeddings**: {model_info['max_position_embeddings']}
"""
model_card += f"""## Intended Use
This model is intended for {task_type.lower()} tasks in {language}.
## Training Data
The model was trained on: {dataset_name}
## Training Procedure
### Training Details
- **Task**: {task_type}
- **Language**: {language}
- **Date**: {datetime.now().strftime('%Y-%m-%d')}
## Usage
```python
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("your-username/{model_name.lower().replace(' ', '-')}")
model = AutoModelForSequenceClassification.from_pretrained("your-username/{model_name.lower().replace(' ', '-')}")
# Example usage
inputs = tokenizer("Your text here", return_tensors="pt")
outputs = model(**inputs)
```
## Limitations and Bias
- This model may have limitations based on the training data
- Please evaluate the model on your specific use case
- Consider potential biases in the training data
## Citation
```bibtex
@misc{{{model_name.lower().replace(' ', '_')}_2024,
author = {{Your Name}},
title = {{{model_name}}},
year = {{2024}},
url = {{https://huggingface.co/your-username/{model_name.lower().replace(' ', '-')}}}
}}
```
## Contact
For questions and comments, please contact [[email protected]](mailto:[email protected])
"""
return model_card
# Gradio ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ •
with gr.Blocks(title="๐Ÿค— Model Card Generator") as demo:
gr.Markdown("# ๐Ÿค— Model Card Generator")
gr.Markdown("๋ชจ๋ธ์˜ ๊ธฐ๋ณธ ์ •๋ณด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์ž๋™์œผ๋กœ Hugging Face ์Šคํƒ€์ผ์˜ ๋ชจ๋ธ ์นด๋“œ๋ฅผ ์ƒ์„ฑํ•ด๋“œ๋ฆฝ๋‹ˆ๋‹ค!")
with gr.Row():
with gr.Column():
gr.Markdown("### ๐Ÿ“ ๋ชจ๋ธ ์ •๋ณด")
config_file = gr.File(
label="config.json ํŒŒ์ผ (์„ ํƒ์‚ฌํ•ญ)",
file_types=[".json"],
type="binary"
)
gr.Markdown("### โœ๏ธ ๊ธฐ๋ณธ ์ •๋ณด")
model_name = gr.Textbox(
label="๋ชจ๋ธ ์ด๋ฆ„",
placeholder="์˜ˆ: Korean-BERT-Sentiment",
value=""
)
short_description = gr.Textbox(
label="์งง์€ ์„ค๋ช… (ํ•œ ์ค„)",
placeholder="์˜ˆ: Korean sentiment analysis model based on BERT",
lines=1
)
model_description = gr.Textbox(
label="์ƒ์„ธ ์„ค๋ช…",
placeholder="์˜ˆ: ํ•œ๊ตญ์–ด ๊ฐ์ • ๋ถ„์„์„ ์œ„ํ•ด fine-tuning๋œ BERT ๋ชจ๋ธ์ž…๋‹ˆ๋‹ค. ๊ธ์ •/๋ถ€์ •/์ค‘๋ฆฝ ๊ฐ์ •์„ ๋ถ„๋ฅ˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.",
lines=3
)
dataset_name = gr.Textbox(
label="ํ›ˆ๋ จ ๋ฐ์ดํ„ฐ์…‹",
placeholder="์˜ˆ: Korean Sentiment Dataset"
)
task_type = gr.Dropdown(
label="ํƒœ์Šคํฌ ํƒ€์ž…",
choices=["Text Classification", "Question Answering", "Text Generation", "Named Entity Recognition", "Text Summarization"],
value="Text Classification"
)
language = gr.Dropdown(
label="์–ธ์–ด",
choices=["Korean", "English", "Multilingual"],
value="Korean"
)
license_type = gr.Dropdown(
label="๋ผ์ด์„ ์Šค",
choices=["apache-2.0", "mit", "cc-by-4.0", "cc-by-nc-4.0", "cc-by-sa-4.0", "bsd-3-clause", "gpl-3.0", "other"],
value="apache-2.0"
)
generate_btn = gr.Button("๐Ÿš€ ๋ชจ๋ธ ์นด๋“œ ์ƒ์„ฑ", variant="primary")
with gr.Column():
gr.Markdown("### ๐Ÿ“„ ์ƒ์„ฑ๋œ ๋ชจ๋ธ ์นด๋“œ")
output = gr.Textbox(
label="Model Card (Markdown)",
lines=25,
max_lines=50,
show_copy_button=True
)
generate_btn.click(
fn=generate_model_card,
inputs=[config_file, model_name, short_description, model_description, dataset_name, task_type, language, license_type],
outputs=output
)
gr.Markdown("### ๐Ÿ’ก ์‚ฌ์šฉ๋ฒ•")
gr.Markdown("""
1. **config.json ํŒŒ์ผ ์—…๋กœ๋“œ** (์„ ํƒ์‚ฌํ•ญ): ๋ชจ๋ธ์˜ config.json ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•˜๋ฉด ์ž๋™์œผ๋กœ ์•„ํ‚คํ…์ฒ˜ ์ •๋ณด๋ฅผ ์ถ”์ถœํ•ฉ๋‹ˆ๋‹ค
2. **๊ธฐ๋ณธ ์ •๋ณด ์ž…๋ ฅ**:
- **๋ชจ๋ธ ์ด๋ฆ„**: Hugging Face์—์„œ ์‚ฌ์šฉํ•  ๋ชจ๋ธ๋ช…
- **์งง์€ ์„ค๋ช…**: ๋ชจ๋ธ ์นด๋“œ ์ƒ๋‹จ์— ํ‘œ์‹œ๋  ํ•œ ์ค„ ์š”์•ฝ
- **์ƒ์„ธ ์„ค๋ช…**: ๋ชจ๋ธ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ์„ค๋ช…
- **๋ผ์ด์„ ์Šค**: ๋ชจ๋ธ์˜ ์‚ฌ์šฉ ๋ผ์ด์„ ์Šค ์„ ํƒ
3. **์ƒ์„ฑ ๋ฒ„ํŠผ ํด๋ฆญ**: ํ‘œ์ค€ํ™”๋œ ๋ชจ๋ธ ์นด๋“œ๊ฐ€ ์ž๋™์œผ๋กœ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค
4. **๋ณต์‚ฌํ•˜์—ฌ ์‚ฌ์šฉ**: ์ƒ์„ฑ๋œ ํ…์ŠคํŠธ๋ฅผ ๋ณต์‚ฌํ•ด์„œ README.md๋กœ ์‚ฌ์šฉํ•˜์„ธ์š”!
**์ฃผ์š” ๋ผ์ด์„ ์Šค ์„ค๋ช…:**
- **apache-2.0**: ์ƒ์—…์  ์‚ฌ์šฉ ๊ฐ€๋Šฅ, ๊ฐ€์žฅ ์ž์œ ๋กœ์šด ๋ผ์ด์„ ์Šค
- **mit**: ๊ฐ„๋‹จํ•˜๊ณ  ์ž์œ ๋กœ์šด ๋ผ์ด์„ ์Šค
- **cc-by-4.0**: ํฌ๋ฆฌ์—์ดํ‹ฐ๋ธŒ ์ปค๋จผ์ฆˆ, ์ถœ์ฒ˜ ํ‘œ์‹œ ํ•„์š”
- **cc-by-nc-4.0**: ๋น„์ƒ์—…์  ์‚ฌ์šฉ๋งŒ ํ—ˆ์šฉ
""")
if __name__ == "__main__":
demo.launch()