MonsterBoyTabs commited on
Commit
bcff14c
·
verified ·
1 Parent(s): a5a441b

requirements.txt

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
+
4
+ # Set page config for Urdu (right-to-left support)
5
+ st.set_page_config(page_title="اردو AI", layout="centered")
6
+
7
+ # Load the Urdu model and tokenizer
8
+ model_name = "m3hrdadfi/mt5-small-finetuned-urdu-sentiment"
9
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
10
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
11
+
12
+ # Custom CSS for Urdu font and RTL support
13
+ st.markdown("""
14
+ <style>
15
+ body {
16
+ font-family: "Noto Sans Urdu", sans-serif;
17
+ direction: rtl;
18
+ text-align: right;
19
+ }
20
+ </style>
21
+ """, unsafe_allow_html=True)
22
+
23
+ # Title
24
+ st.title("🕌 اردو AI مددگار")
25
+
26
+ # Chat history
27
+ if "messages" not in st.session_state:
28
+ st.session_state.messages = []
29
+
30
+ # Display chat history
31
+ for message in st.session_state.messages:
32
+ with st.chat_message(message["role"]):
33
+ st.markdown(message["content"], unsafe_allow_html=True)
34
+
35
+ # User input
36
+ user_input = st.chat_input("اپنا پیغام یہاں لکھیں...")
37
+
38
+ # Generate response
39
+ if user_input:
40
+ # Add user message to history
41
+ st.session_state.messages.append({"role": "user", "content": user_input})
42
+
43
+ # Tokenize input and generate response
44
+ inputs = tokenizer.encode(user_input, return_tensors="pt")
45
+ outputs = model.generate(inputs, max_length=100)
46
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
47
+
48
+ # Add AI response to history
49
+ st.session_state.messages.append({"role": "assistant", "content": response})
50
+
51
+ # Rerun to update the UI
52
+ st.rerun()