Spaces:
Runtime error
Runtime error
ilhamsyahids
commited on
Commit
•
6a4c78f
1
Parent(s):
9b05b64
add aya model
Browse filesSigned-off-by: Ilham Syahid S <ilhamsyahids@gmail.com>
- README.md +5 -5
- app.py +128 -0
- requirements.txt +3 -0
README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
---
|
2 |
title: CohereAya
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: streamlit
|
7 |
sdk_version: 1.31.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
|
11 |
|
12 |
-
|
|
|
1 |
---
|
2 |
title: CohereAya
|
3 |
+
emoji: 💬
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: yellow
|
6 |
sdk: streamlit
|
7 |
sdk_version: 1.31.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
license: openrail
|
11 |
|
12 |
+
---
|
app.py
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, pipeline
|
3 |
+
|
4 |
+
def main():
|
5 |
+
st.set_page_config(page_title="LinguaSphere: Aya by CohereAI", layout="wide")
|
6 |
+
|
7 |
+
st.title("LinguaSphere: Aya by CohereAI")
|
8 |
+
|
9 |
+
# Load translation model and tokenizer
|
10 |
+
translation_checkpoint = "CohereForAI/aya-101"
|
11 |
+
translation_tokenizer = AutoTokenizer.from_pretrained(translation_checkpoint)
|
12 |
+
translation_model = AutoModelForSeq2SeqLM.from_pretrained(translation_checkpoint)
|
13 |
+
|
14 |
+
# Load sentiment analysis model
|
15 |
+
sentiment_analysis_pipeline = pipeline("sentiment-analysis", model="CohereForAI/aya-101")
|
16 |
+
|
17 |
+
# Load named entity recognition (NER) model
|
18 |
+
ner_pipeline = pipeline("ner", model="CohereForAI/aya-101")
|
19 |
+
|
20 |
+
# Load summarization model
|
21 |
+
summarization_pipeline = pipeline("summarization", model="CohereForAI/aya-101")
|
22 |
+
|
23 |
+
# Sidebar options
|
24 |
+
st.sidebar.title("Options")
|
25 |
+
show_model_info = st.sidebar.checkbox("Show Model Information")
|
26 |
+
show_task_description = st.sidebar.checkbox("Show Task Description")
|
27 |
+
show_about = st.sidebar.checkbox("About")
|
28 |
+
|
29 |
+
if show_about:
|
30 |
+
st.sidebar.subheader("About")
|
31 |
+
st.sidebar.markdown(
|
32 |
+
"LinguaSphere is a Streamlit app powered by Aya, a multilingual model developed by CohereAI."
|
33 |
+
)
|
34 |
+
|
35 |
+
if show_model_info:
|
36 |
+
st.sidebar.subheader("Model Information")
|
37 |
+
st.sidebar.markdown(
|
38 |
+
"""
|
39 |
+
The Aya model is a massively multilingual generative language model developed by Cohere For AI.
|
40 |
+
It is capable of performing various natural language processing tasks such as translation, sentiment analysis,
|
41 |
+
named entity recognition, and summarization.
|
42 |
+
"""
|
43 |
+
)
|
44 |
+
|
45 |
+
if show_task_description:
|
46 |
+
st.sidebar.subheader("Task Descriptions")
|
47 |
+
st.sidebar.markdown(
|
48 |
+
"""
|
49 |
+
- **Translation:** Translate text from one language to another.
|
50 |
+
- **Text Generation:** Generate text based on a prompt.
|
51 |
+
- **Sentiment Analysis:** Analyze the sentiment of text.
|
52 |
+
- **Named Entity Recognition:** Identify named entities in text.
|
53 |
+
- **Summarization:** Generate a summary of text.
|
54 |
+
"""
|
55 |
+
)
|
56 |
+
|
57 |
+
task = st.selectbox(
|
58 |
+
"Select Task",
|
59 |
+
[
|
60 |
+
"Translation",
|
61 |
+
"Text Generation",
|
62 |
+
"Sentiment Analysis",
|
63 |
+
"Named Entity Recognition",
|
64 |
+
"Summarization",
|
65 |
+
],
|
66 |
+
)
|
67 |
+
|
68 |
+
if task == "Translation":
|
69 |
+
source_language = st.selectbox(
|
70 |
+
"Source Language", ["English", "Turkish", "Hindi"]
|
71 |
+
)
|
72 |
+
target_language = st.selectbox(
|
73 |
+
"Target Language", ["Nepali", "Turkish", "English"]
|
74 |
+
)
|
75 |
+
source_text = st.text_area("Enter text in " + source_language, "")
|
76 |
+
|
77 |
+
if st.button("Translate"):
|
78 |
+
source_text = source_text.strip()
|
79 |
+
if source_language == "English":
|
80 |
+
source_text = "Translate to " + target_language + ": " + source_text
|
81 |
+
else:
|
82 |
+
source_text = source_text + "।"
|
83 |
+
inputs = translation_tokenizer.encode(source_text, return_tensors="pt")
|
84 |
+
outputs = translation_model.generate(inputs, max_length=128)
|
85 |
+
translated_text = translation_tokenizer.decode(
|
86 |
+
outputs[0], skip_special_tokens=True
|
87 |
+
)
|
88 |
+
st.write("Translated text in " + target_language + ":", translated_text)
|
89 |
+
|
90 |
+
elif task == "Text Generation":
|
91 |
+
prompt = st.text_area("Enter prompt for text generation", "")
|
92 |
+
language = st.selectbox("Select Language", ["English", "Turkish", "Hindi"])
|
93 |
+
if st.button("Generate"):
|
94 |
+
prompt = prompt.strip()
|
95 |
+
if language == "English":
|
96 |
+
prompt = "Generate text: " + prompt
|
97 |
+
elif language == "Hindi":
|
98 |
+
prompt = prompt + "।"
|
99 |
+
inputs = translation_tokenizer.encode(prompt, return_tensors="pt")
|
100 |
+
outputs = translation_model.generate(inputs, max_length=128)
|
101 |
+
generated_text = translation_tokenizer.decode(
|
102 |
+
outputs[0], skip_special_tokens=True
|
103 |
+
)
|
104 |
+
st.write("Generated text:", generated_text)
|
105 |
+
|
106 |
+
elif task == "Sentiment Analysis":
|
107 |
+
text = st.text_area("Enter text for sentiment analysis", "")
|
108 |
+
if st.button("Analyze Sentiment"):
|
109 |
+
result = sentiment_analysis_pipeline(text)
|
110 |
+
st.write("Sentiment:", result[0]["label"])
|
111 |
+
|
112 |
+
elif task == "Named Entity Recognition":
|
113 |
+
text = st.text_area("Enter text for named entity recognition", "")
|
114 |
+
if st.button("Recognize Entities"):
|
115 |
+
entities = ner_pipeline(text)
|
116 |
+
st.write("Entities:")
|
117 |
+
for entity in entities:
|
118 |
+
st.write(entity)
|
119 |
+
|
120 |
+
elif task == "Summarization":
|
121 |
+
text = st.text_area("Enter text for summarization", "")
|
122 |
+
if st.button("Summarize"):
|
123 |
+
summary = summarization_pipeline(text)
|
124 |
+
st.write("Summary:", summary[0]["summary_text"])
|
125 |
+
|
126 |
+
|
127 |
+
if __name__ == "__main__":
|
128 |
+
main()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
transformers
|
3 |
+
torch
|