Altayebhssab commited on
Commit
58611a7
·
1 Parent(s): 9249c82

Add application file

Browse files
Files changed (1) hide show
  1. app.py +85 -0
app.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
+ import time
4
+ import torch
5
+
6
+ # إعداد النموذج والمُرمز
7
+ @st.cache_resource
8
+ def load_model():
9
+ tokenizer = AutoTokenizer.from_pretrained("Salesforce/codet5-base")
10
+ model = AutoModelForSeq2SeqLM.from_pretrained("Salesforce/codet5-base")
11
+ return tokenizer, model
12
+
13
+ tokenizer, model = load_model()
14
+
15
+ # واجهة المستخدم الرئيسية
16
+ st.title("AI Code Assistant")
17
+ st.sidebar.title("Options")
18
+
19
+ # الأقسام الرئيسية
20
+ section = st.sidebar.radio(
21
+ "Choose a Section",
22
+ ("Generate Code", "Train Model", "Prompt Engineer", "Optimize Model")
23
+ )
24
+
25
+ # 1. توليد الكود بناءً على وصف النص
26
+ if section == "Generate Code":
27
+ st.header("Generate Code from Description")
28
+ prompt = st.text_area("Enter your description:", "Write a Python function to reverse a string.")
29
+
30
+ if st.button("Generate Code"):
31
+ with st.spinner("Generating code..."):
32
+ inputs = tokenizer(prompt, return_tensors="pt")
33
+ outputs = model.generate(inputs["input_ids"], max_length=100)
34
+ code = tokenizer.decode(outputs[0], skip_special_tokens=True)
35
+ st.code(code, language="python")
36
+
37
+ # 2. تدريب النموذج
38
+ elif section == "Train Model":
39
+ st.header("Train the Model")
40
+ st.write("Upload your dataset to fine-tune the model.")
41
+
42
+ uploaded_file = st.file_uploader("Upload Dataset (JSON/CSV):")
43
+ if uploaded_file is not None:
44
+ st.write("Dataset uploaded successfully!")
45
+ # يمكنك إضافة الكود لتحليل البيانات أو عرض عينات منها هنا.
46
+
47
+ if st.button("Start Training"):
48
+ with st.spinner("Training the model..."):
49
+ time.sleep(5) # محاكاة وقت التدريب
50
+ st.success("Model training completed!")
51
+
52
+ # 3. تحسين الـ Prompts
53
+ elif section == "Prompt Engineer":
54
+ st.header("Prompt Engineering")
55
+ st.write("Experiment with different prompts to get the best results.")
56
+
57
+ prompt_input = st.text_area("Enter a prompt:", "Explain this code: def add(a, b): return a + b")
58
+ if st.button("Test Prompt"):
59
+ with st.spinner("Testing the prompt..."):
60
+ inputs = tokenizer(prompt_input, return_tensors="pt")
61
+ outputs = model.generate(inputs["input_ids"], max_length=100)
62
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
63
+ st.write("Model Response:")
64
+ st.code(response)
65
+
66
+ # 4. تحسين أداء النموذج
67
+ elif section == "Optimize Model":
68
+ st.header("Optimize Model Performance")
69
+ st.write("Adjust model parameters to improve performance.")
70
+
71
+ learning_rate = st.slider("Learning Rate:", 1e-5, 1e-3, 1e-4, step=1e-5)
72
+ batch_size = st.slider("Batch Size:", 1, 64, 8, step=1)
73
+ epochs = st.slider("Number of Epochs:", 1, 10, 3)
74
+
75
+ if st.button("Apply Settings"):
76
+ st.write(f"Settings Applied:\n- Learning Rate: {learning_rate}\n- Batch Size: {batch_size}\n- Epochs: {epochs}")
77
+ st.success("Optimization settings saved!")
78
+
79
+ ---
80
+
81
+ ### **الخطوة الثالثة: تشغيل التطبيق**
82
+
83
+ - قم بتشغيل التطبيق باستخدام الأمر:
84
+ ```bash
85
+ streamlit run app.py