Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,11 +4,7 @@ from transformers import (
|
|
4 |
GPT2LMHeadModel, GPT2Tokenizer,
|
5 |
pipeline
|
6 |
)
|
7 |
-
|
8 |
-
# App title
|
9 |
st.title("Multi Chatbot")
|
10 |
-
|
11 |
-
# Define models and descriptions
|
12 |
models = {
|
13 |
"English to French": {
|
14 |
"name": "Helsinki-NLP/opus-mt-en-fr",
|
@@ -24,7 +20,6 @@ models = {
|
|
24 |
}
|
25 |
}
|
26 |
|
27 |
-
# Sidebar: Model selection
|
28 |
st.sidebar.header("Choose a Model")
|
29 |
selected_model_key = st.sidebar.radio("Select a Model:", list(models.keys()))
|
30 |
model_name = models[selected_model_key]["name"]
|
@@ -32,7 +27,6 @@ model_description = models[selected_model_key]["description"]
|
|
32 |
|
33 |
st.sidebar.markdown(f"### Model Description\n{model_description}")
|
34 |
|
35 |
-
# Cache model loading for efficiency
|
36 |
@st.cache_resource
|
37 |
def load_english_to_french():
|
38 |
tokenizer = MarianTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-fr")
|
@@ -50,7 +44,7 @@ def load_story_generator():
|
|
50 |
tokenizer.pad_token = tokenizer.eos_token # Set pad token to EOS token
|
51 |
return tokenizer, model
|
52 |
|
53 |
-
|
54 |
if selected_model_key == "English to French":
|
55 |
st.write("Loading English to French model...")
|
56 |
en_fr_tokenizer, en_fr_model = load_english_to_french()
|
@@ -66,7 +60,6 @@ elif selected_model_key == "Story Generator":
|
|
66 |
story_gen_tokenizer, story_gen_model = load_story_generator()
|
67 |
st.write("Story Generator model loaded successfully.")
|
68 |
|
69 |
-
# User input
|
70 |
user_input = st.text_input("Enter your query:")
|
71 |
|
72 |
if user_input:
|
|
|
4 |
GPT2LMHeadModel, GPT2Tokenizer,
|
5 |
pipeline
|
6 |
)
|
|
|
|
|
7 |
st.title("Multi Chatbot")
|
|
|
|
|
8 |
models = {
|
9 |
"English to French": {
|
10 |
"name": "Helsinki-NLP/opus-mt-en-fr",
|
|
|
20 |
}
|
21 |
}
|
22 |
|
|
|
23 |
st.sidebar.header("Choose a Model")
|
24 |
selected_model_key = st.sidebar.radio("Select a Model:", list(models.keys()))
|
25 |
model_name = models[selected_model_key]["name"]
|
|
|
27 |
|
28 |
st.sidebar.markdown(f"### Model Description\n{model_description}")
|
29 |
|
|
|
30 |
@st.cache_resource
|
31 |
def load_english_to_french():
|
32 |
tokenizer = MarianTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-fr")
|
|
|
44 |
tokenizer.pad_token = tokenizer.eos_token # Set pad token to EOS token
|
45 |
return tokenizer, model
|
46 |
|
47 |
+
|
48 |
if selected_model_key == "English to French":
|
49 |
st.write("Loading English to French model...")
|
50 |
en_fr_tokenizer, en_fr_model = load_english_to_french()
|
|
|
60 |
story_gen_tokenizer, story_gen_model = load_story_generator()
|
61 |
st.write("Story Generator model loaded successfully.")
|
62 |
|
|
|
63 |
user_input = st.text_input("Enter your query:")
|
64 |
|
65 |
if user_input:
|