George-API commited on
Commit
b4b3dd2
·
verified ·
1 Parent(s): 4dfe8a5

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +115 -76
app.py CHANGED
@@ -1,76 +1,115 @@
1
- import gradio as gr
2
- import os
3
- from dotenv import load_dotenv
4
-
5
- # Load environment variables
6
- load_dotenv()
7
-
8
- # Model details
9
- MODEL_NAME = "unsloth/DeepSeek-R1-Distill-Qwen-14B-bnb-4bit"
10
- SPACE_NAME = os.getenv("HF_SPACE_NAME", "qwen4bit")
11
-
12
- def generate_response(prompt, max_new_tokens=256):
13
- """
14
- This is a placeholder function that will be replaced with actual model inference
15
- after fine-tuning is complete.
16
- """
17
- # Currently returns a placeholder message
18
- return f"""[Placeholder Response]
19
- This is a demo of the {MODEL_NAME} model.
20
- Once fine-tuning is complete, this will respond to:
21
- "{prompt}"
22
-
23
- This space will be updated with the fine-tuned model."""
24
-
25
- # Create the Gradio interface
26
- with gr.Blocks(title=f"Fine-tuned {MODEL_NAME}") as demo:
27
- gr.Markdown(f"""
28
- # Fine-tuned DeepSeek-R1-Distill-Qwen-14B Model
29
-
30
- This space will host the fine-tuned version of `{MODEL_NAME}` once training is complete.
31
-
32
- **Model Details**:
33
- - Base model: `{MODEL_NAME}`
34
- - Fine-tuned on: `phi4-cognitive-dataset`
35
- - 4-bit quantized (already, not further quantized)
36
-
37
- **Current Status**: Preparing for fine-tuning
38
- """)
39
-
40
- with gr.Row():
41
- with gr.Column():
42
- input_text = gr.Textbox(
43
- label="Enter your prompt",
44
- placeholder="Type your prompt here...",
45
- lines=4
46
- )
47
- max_tokens = gr.Slider(
48
- minimum=32,
49
- maximum=1024,
50
- value=256,
51
- step=32,
52
- label="Max new tokens"
53
- )
54
- submit_btn = gr.Button("Generate Response")
55
-
56
- with gr.Column():
57
- output_text = gr.Textbox(
58
- label="Model Response",
59
- lines=10
60
- )
61
-
62
- submit_btn.click(
63
- fn=generate_response,
64
- inputs=[input_text, max_tokens],
65
- outputs=output_text
66
- )
67
-
68
- gr.Markdown("""
69
- ### Note
70
- This is a placeholder application. The actual fine-tuned model will be deployed
71
- to this space once training is complete.
72
- """)
73
-
74
- # Launch the app
75
- if __name__ == "__main__":
76
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import json
4
+ import torch
5
+ from dotenv import load_dotenv
6
+ import logging
7
+
8
+ # Configure logging
9
+ logging.basicConfig(
10
+ level=logging.INFO,
11
+ format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
12
+ handlers=[
13
+ logging.StreamHandler(),
14
+ logging.FileHandler("app.log")
15
+ ]
16
+ )
17
+ logger = logging.getLogger(__name__)
18
+
19
+ # Load environment variables
20
+ load_dotenv()
21
+
22
+ # Load config file
23
+ def load_config(config_path="transformers_config.json"):
24
+ try:
25
+ with open(config_path, 'r') as f:
26
+ config = json.load(f)
27
+ return config
28
+ except Exception as e:
29
+ logger.error(f"Error loading config: {str(e)}")
30
+ return {}
31
+
32
+ # Load configuration
33
+ config = load_config()
34
+ model_config = config.get("model_config", {})
35
+
36
+ # Model details from config
37
+ MODEL_NAME = model_config.get("model_name_or_path", "unsloth/DeepSeek-R1-Distill-Qwen-14B-bnb-4bit")
38
+ SPACE_NAME = os.getenv("HF_SPACE_NAME", "phi4training")
39
+ TRAINING_ACTIVE = os.path.exists("TRAINING_ACTIVE")
40
+
41
+ # Create Gradio interface - training status only, no model outputs
42
+ with gr.Blocks(css="footer {visibility: hidden}") as demo:
43
+ gr.Markdown(f"# {SPACE_NAME}: Training Status Dashboard")
44
+
45
+ with gr.Row():
46
+ with gr.Column():
47
+ status = gr.Markdown(
48
+ f"""
49
+ ## Research Training Phase Active
50
+
51
+ **Model**: {MODEL_NAME}
52
+ **Dataset**: phi4-cognitive-dataset
53
+
54
+ This is a multidisciplinary research training phase. The model is not available for interactive use.
55
+
56
+ ### Training Configuration:
57
+ - **Epochs**: {config.get("training_config", {}).get("num_train_epochs", 3)}
58
+ - **Batch Size**: {config.get("training_config", {}).get("per_device_train_batch_size", 2)}
59
+ - **Gradient Accumulation Steps**: {config.get("training_config", {}).get("gradient_accumulation_steps", 4)}
60
+ - **Learning Rate**: {config.get("training_config", {}).get("learning_rate", 2e-5)}
61
+ - **Max Sequence Length**: {config.get("training_config", {}).get("max_seq_length", 2048)}
62
+
63
+ ### Training Status:
64
+ {"🟢 Training in progress" if TRAINING_ACTIVE else "⚪ Training not currently active"}
65
+
66
+ ⚠️ **NOTE**: This space does not provide model outputs during the research training phase.
67
+ """
68
+ )
69
+
70
+ # Add a refresh button to check status
71
+ refresh_btn = gr.Button("Refresh Status")
72
+
73
+ def refresh_status():
74
+ # Re-check if training is active
75
+ training_active = os.path.exists("TRAINING_ACTIVE")
76
+ return f"""
77
+ ## Research Training Phase Active
78
+
79
+ **Model**: {MODEL_NAME}
80
+ **Dataset**: phi4-cognitive-dataset
81
+
82
+ This is a multidisciplinary research training phase. The model is not available for interactive use.
83
+
84
+ ### Training Configuration:
85
+ - **Epochs**: {config.get("training_config", {}).get("num_train_epochs", 3)}
86
+ - **Batch Size**: {config.get("training_config", {}).get("per_device_train_batch_size", 2)}
87
+ - **Gradient Accumulation Steps**: {config.get("training_config", {}).get("gradient_accumulation_steps", 4)}
88
+ - **Learning Rate**: {config.get("training_config", {}).get("learning_rate", 2e-5)}
89
+ - **Max Sequence Length**: {config.get("training_config", {}).get("max_seq_length", 2048)}
90
+
91
+ ### Training Status:
92
+ {"🟢 Training in progress" if training_active else "⚪ Training not currently active"}
93
+
94
+ ⚠️ **NOTE**: This space does not provide model outputs during the research training phase.
95
+ """
96
+
97
+ refresh_btn.click(refresh_status, outputs=status)
98
+
99
+ gr.Markdown("""
100
+ ### Research Training Information
101
+ This model is being fine-tuned on research-focused datasets and is not available for interactive querying.
102
+ Training logs are available to authorized researchers only.
103
+ """)
104
+
105
+ # Launch the interface
106
+ if __name__ == "__main__":
107
+ # Create an empty TRAINING_ACTIVE file to indicate training is in progress
108
+ # This would be managed by the actual training script
109
+ if not os.path.exists("TRAINING_ACTIVE"):
110
+ with open("TRAINING_ACTIVE", "w") as f:
111
+ f.write("Training in progress")
112
+
113
+ # Start Gradio with minimal features
114
+ logger.info("Starting training status dashboard")
115
+ demo.launch(share=False, enable_queue=False)