Spaces:
Sleeping
Sleeping
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() |