Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import json | |
| from datetime import datetime | |
| # ์์ ๋ฐ์ดํฐ ์ ์ฅ์ | |
| users = [] | |
| contributions = [] | |
| nfts = [] | |
| def create_user(name, email): | |
| user = { | |
| 'id': f'user_{len(users) + 1}', | |
| 'name': name, | |
| 'email': email, | |
| 'points': 0, | |
| 'level': 1, | |
| 'created_at': datetime.now().isoformat() | |
| } | |
| users.append(user) | |
| return json.dumps(user, indent=2) | |
| def create_contribution(user_id, contribution_type, description): | |
| # ํฌ์ธํธ ๊ณ์ฐ | |
| points = { | |
| 'POST_CREATION': 10, | |
| 'COMMENT': 5, | |
| 'REVIEW': 15, | |
| 'BUG_REPORT': 20, | |
| 'FEATURE_SUGGESTION': 15, | |
| 'CODE_CONTRIBUTION': 30 | |
| } | |
| # ์ฌ์ฉ์ ์ฐพ๊ธฐ | |
| user = next((u for u in users if u['id'] == user_id), None) | |
| if not user: | |
| return json.dumps({'error': 'User not found'}) | |
| # ๊ธฐ์ฌ๋ ์์ฑ | |
| contribution = { | |
| 'id': f'contrib_{len(contributions) + 1}', | |
| 'user_id': user_id, | |
| 'type': contribution_type, | |
| 'description': description, | |
| 'points': points.get(contribution_type, 0), | |
| 'created_at': datetime.now().isoformat() | |
| } | |
| contributions.append(contribution) | |
| # ์ฌ์ฉ์ ํฌ์ธํธ ์ ๋ฐ์ดํธ | |
| user['points'] += contribution['points'] | |
| user['level'] = (user['points'] // 100) + 1 | |
| return json.dumps(contribution, indent=2) | |
| def mint_nft(title, description, rarity): | |
| if not users: | |
| return json.dumps({'error': 'No users available'}) | |
| nft = { | |
| 'id': f'nft_{len(nfts) + 1}', | |
| 'title': title, | |
| 'description': description, | |
| 'rarity': rarity, | |
| 'owner_id': users[0]['id'], | |
| 'created_at': datetime.now().isoformat() | |
| } | |
| nfts.append(nft) | |
| return json.dumps(nft, indent=2) | |
| def get_leaderboard(): | |
| sorted_users = sorted(users, key=lambda x: x['points'], reverse=True) | |
| leaderboard = [] | |
| for i, user in enumerate(sorted_users, 1): | |
| leaderboard.append({ | |
| 'rank': i, | |
| 'name': user['name'], | |
| 'points': user['points'], | |
| 'level': user['level'] | |
| }) | |
| return json.dumps(leaderboard, indent=2) | |
| # Gradio ์ธํฐํ์ด์ค ์์ฑ | |
| with gr.Blocks(title="AI Tree Incentive System") as demo: | |
| gr.Markdown(""" | |
| # ๐ฏ AI Tree Incentive System | |
| ๋ธ๋ก๊ทธ ๊ธฐ์ฌ๋ ๊ธฐ๋ฐ์ ์ธ์ผํฐ๋ธ ์์คํ ์ ๋๋ค. | |
| """) | |
| with gr.Tab("์ฌ์ฉ์ ๊ด๋ฆฌ"): | |
| with gr.Row(): | |
| with gr.Column(): | |
| name_input = gr.Textbox(label="์ด๋ฆ") | |
| email_input = gr.Textbox(label="์ด๋ฉ์ผ") | |
| create_user_btn = gr.Button("์ฌ์ฉ์ ์์ฑ") | |
| with gr.Column(): | |
| user_output = gr.JSON(label="์์ฑ๋ ์ฌ์ฉ์ ์ ๋ณด") | |
| create_user_btn.click( | |
| create_user, | |
| inputs=[name_input, email_input], | |
| outputs=user_output | |
| ) | |
| with gr.Tab("๊ธฐ์ฌ๋ ๋ฑ๋ก"): | |
| with gr.Row(): | |
| with gr.Column(): | |
| user_id_input = gr.Textbox(label="์ฌ์ฉ์ ID") | |
| contrib_type = gr.Dropdown( | |
| choices=["POST_CREATION", "COMMENT", "REVIEW", "BUG_REPORT", "FEATURE_SUGGESTION", "CODE_CONTRIBUTION"], | |
| label="๊ธฐ์ฌ ์ ํ" | |
| ) | |
| desc_input = gr.Textbox(label="์ค๋ช ") | |
| create_contrib_btn = gr.Button("๊ธฐ์ฌ๋ ๋ฑ๋ก") | |
| with gr.Column(): | |
| contrib_output = gr.JSON(label="๊ธฐ์ฌ๋ ์ ๋ณด") | |
| create_contrib_btn.click( | |
| create_contribution, | |
| inputs=[user_id_input, contrib_type, desc_input], | |
| outputs=contrib_output | |
| ) | |
| with gr.Tab("NFT ๋ฐํ"): | |
| with gr.Row(): | |
| with gr.Column(): | |
| nft_title = gr.Textbox(label="NFT ์ ๋ชฉ") | |
| nft_desc = gr.Textbox(label="NFT ์ค๋ช ") | |
| nft_rarity = gr.Dropdown( | |
| choices=["COMMON", "RARE", "EPIC", "LEGENDARY"], | |
| label="ํฌ๊ท๋" | |
| ) | |
| mint_nft_btn = gr.Button("NFT ๋ฐํ") | |
| with gr.Column(): | |
| nft_output = gr.JSON(label="๋ฐํ๋ NFT ์ ๋ณด") | |
| mint_nft_btn.click( | |
| mint_nft, | |
| inputs=[nft_title, nft_desc, nft_rarity], | |
| outputs=nft_output | |
| ) | |
| with gr.Tab("๋ฆฌ๋๋ณด๋"): | |
| refresh_btn = gr.Button("์๋ก๊ณ ์นจ") | |
| leaderboard_output = gr.JSON(label="๋ฆฌ๋๋ณด๋") | |
| refresh_btn.click( | |
| get_leaderboard, | |
| inputs=[], | |
| outputs=leaderboard_output | |
| ) | |
| demo.launch() |