Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from transformers import MarianMTModel, MarianTokenizer
|
4 |
+
|
5 |
+
# Load the model and tokenizer
|
6 |
+
model_name = 'Helsinki-NLP/opus-mt-en-ur'
|
7 |
+
model = MarianMTModel.from_pretrained(model_name)
|
8 |
+
tokenizer = MarianTokenizer.from_pretrained(model_name)
|
9 |
+
|
10 |
+
# Function to translate text from English to Urdu
|
11 |
+
def translate_text(text):
|
12 |
+
inputs = tokenizer(text, return_tensors="pt", padding=True)
|
13 |
+
translated = model.generate(**inputs)
|
14 |
+
return tokenizer.decode(translated[0], skip_special_tokens=True)
|
15 |
+
|
16 |
+
# Streamlit app
|
17 |
+
st.title("Diabetes Dataset Translator")
|
18 |
+
|
19 |
+
# Upload CSV file
|
20 |
+
uploaded_file = st.file_uploader("Upload your CSV file", type=["csv"])
|
21 |
+
if uploaded_file:
|
22 |
+
# Read the file into a pandas DataFrame
|
23 |
+
data = pd.read_csv(uploaded_file)
|
24 |
+
|
25 |
+
# Translate questions and answers
|
26 |
+
if 'Question' in data.columns and 'Answer' in data.columns:
|
27 |
+
data['Question_Urdu'] = data['Question'].apply(translate_text)
|
28 |
+
data['Answer_Urdu'] = data['Answer'].apply(translate_text)
|
29 |
+
|
30 |
+
# Display the translated dataframe
|
31 |
+
st.write(data)
|
32 |
+
|
33 |
+
# Provide option to download the translated CSV
|
34 |
+
translated_file = data.to_csv(index=False)
|
35 |
+
st.download_button("Download Translated CSV", translated_file, "Diabetes_Translated_Urdu.csv")
|
36 |
+
else:
|
37 |
+
st.error("CSV file must contain 'Question' and 'Answer' columns")
|