aimad12 commited on
Commit
b1a239a
·
verified ·
1 Parent(s): 0ea4960

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+
4
+ # تحميل النموذج والTokenizer
5
+ @st.cache_resource # لتخزين النموذج في الذاكرة المؤقتة
6
+ def load_model():
7
+ model_name = "microsoft/Phi-4-mini-instruct"
8
+ model = AutoModelForCausalLM.from_pretrained(model_name)
9
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
10
+ return model, tokenizer
11
+
12
+ model, tokenizer = load_model()
13
+
14
+ # واجهة Streamlit
15
+ st.title("Phi-4-mini-instruct Chatbot")
16
+ st.write("تفاعل مع نموذج Phi-4-mini-instruct من Microsoft.")
17
+
18
+ # إدخال النص
19
+ user_input = st.text_input("أدخل نصك هنا:")
20
+
21
+ # توليد النص
22
+ if user_input:
23
+ inputs = tokenizer(user_input, return_tensors="pt")
24
+ outputs = model.generate(**inputs, max_new_tokens=100)
25
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
26
+ st.write("النموذج يقول:", response)