Shirjannn commited on
Commit
88a2e7f
·
verified ·
1 Parent(s): a22806a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +87 -32
app.py CHANGED
@@ -1,32 +1,87 @@
1
- import gradio as gr
2
- import time
3
-
4
- def analyze_skin(text_input, image_input=None):
5
- time.sleep(2)
6
- if image_input:
7
- return "نتیجه تحلیل تصویر: مشکل پوستی تشخیص داده شد"
8
- return f"پاسخ به متن: {text_input}"
9
-
10
- # ساخت اینترفیس ساده‌تر
11
- with gr.Blocks() as demo:
12
- with gr.Tab("مشاوره متنی"):
13
- gr.ChatInterface(
14
- analyze_skin,
15
- examples=["جوش صورت", "لک پوستی"],
16
- cache_examples=False # غیرفعال کردن کش
17
- )
18
-
19
- with gr.Tab("تحلیل تصویر"):
20
- gr.Markdown("## تصویر خود را آپلود کنید")
21
- img_input = gr.Image()
22
- analyze_btn = gr.Button("تحلیل")
23
- output = gr.Textbox()
24
-
25
- analyze_btn.click(
26
- lambda img: analyze_skin("", img),
27
- inputs=img_input,
28
- outputs=output
29
- )
30
-
31
- # تغییر مهم: اضافه کردن share=True
32
- demo.launch(share=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ===============================
2
+ # Derma Space: Dataset Prep & HF Upload
3
+ # ===============================
4
+
5
+ !pip install datasets huggingface_hub --quiet
6
+
7
+ import json
8
+ import random
9
+ import os
10
+ from datasets import load_dataset
11
+ from huggingface_hub import HfApi, login, upload_file
12
+
13
+ # ------------------------
14
+ # 1️⃣ ورود با Secret
15
+ # ------------------------
16
+ hf_token = os.environ["HF_TOKEN"] # توکن باید در Secrets Space اضافه شده باشد
17
+ login(token=hf_token)
18
+
19
+ # ------------------------
20
+ # 2️⃣ بارگذاری دیتاست عمومی
21
+ # ------------------------
22
+ print("Loading DailyDialog...")
23
+ dd = load_dataset("daily_dialog")['train']
24
+ dd_examples = [{"domain":"general","context":conv[i],"response":conv[i+1]}
25
+ for conv in dd['dialog'] for i in range(len(conv)-1)]
26
+
27
+ print("Loading Persona-Chat...")
28
+ pc = load_dataset("persona_chat", "self_original")['train']
29
+ pc_examples = [{"domain":"general","context":conv['utterances'][i]['text'],
30
+ "response":conv['utterances'][i+1]['text']}
31
+ for conv in pc for i in range(len(conv['utterances'])-1)]
32
+
33
+ general_examples = dd_examples + pc_examples
34
+ random.shuffle(general_examples)
35
+ general_examples = general_examples[:5000] # نمونه‌گیری
36
+
37
+ # ------------------------
38
+ # 3️⃣ دیتاست تخصصی درماتولوژی
39
+ # ------------------------
40
+ print("Loading Dermatology QA (Mreeb)...")
41
+ derma = load_dataset("Mreeb/Dermatology-Question-Answer-Dataset-For-Fine-Tuning")['train']
42
+ derma_examples = [{"domain":"dermatology","context":item['question'],"response":item['answer']}
43
+ for item in derma]
44
+
45
+ print("Loading MedQuAD...")
46
+ medquad = load_dataset("pythonafroz/MedQuAD")['train']
47
+ derma_keywords = ["skin", "eczema", "psoriasis", "dermatitis", "melanoma", "acne", "rash"]
48
+ medquad_derma = [{"domain":"dermatology","context":item['question'],"response":item['answer']}
49
+ for item in medquad if any(k in item['question'].lower() for k in derma_keywords)]
50
+ random.shuffle(medquad_derma)
51
+ medquad_derma = medquad_derma[:500]
52
+
53
+ dermatology_examples = derma_examples + medquad_derma
54
+ random.shuffle(dermatology_examples)
55
+
56
+ # ------------------------
57
+ # 4️⃣ ترکیب نهایی
58
+ # ------------------------
59
+ all_examples = general_examples + dermatology_examples
60
+ random.shuffle(all_examples)
61
+
62
+ # ------------------------
63
+ # 5️⃣ ذخیره به JSONL
64
+ # ------------------------
65
+ output_file = "derma_chat_mix.jsonl"
66
+ with open(output_file, 'w', encoding='utf-8') as f:
67
+ for ex in all_examples:
68
+ f.write(json.dumps(ex, ensure_ascii=False) + "\n")
69
+
70
+ print(f"✅ Dataset saved locally as {output_file} ({len(all_examples)} examples)")
71
+
72
+ # ------------------------
73
+ # 6️⃣ آپلود به Hugging Face Hub
74
+ # ------------------------
75
+ repo_id = "username/Derma" # نام کاربری خودت + نام Space
76
+ api = HfApi()
77
+ api.create_repo(repo_id=repo_id, repo_type="dataset", exist_ok=True)
78
+
79
+ upload_file(
80
+ path_or_fileobj=output_file,
81
+ path_in_repo=output_file,
82
+ repo_id=repo_id,
83
+ repo_type="dataset",
84
+ commit_message="Initial upload of text-based chat dataset"
85
+ )
86
+
87
+ print(f"✅ Dataset uploaded to Hugging Face Hub: https://huggingface.co/datasets/{repo_id}")