acecalisto3 commited on
Commit
dfa271d
·
verified ·
1 Parent(s): d9a330b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -3
app.py CHANGED
@@ -3,10 +3,13 @@ import os
3
  import subprocess
4
  import random
5
  import string
6
- from huggingface_hub import cached_download, hf_hub_url
7
  from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
8
  import black
9
  import pylint
 
 
 
10
 
11
  # Define functions for each feature
12
 
@@ -148,11 +151,43 @@ def generate_code(idea):
148
 
149
  return generated_code
150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  # Streamlit App
152
  st.title("CodeCraft: Your AI-Powered Development Toolkit")
153
 
154
  # Workspace Selection
155
- st.sidebar.header("Select Workspace") # Use st.sidebar.selectbox
156
  project_name = st.sidebar.selectbox("Choose a project", os.listdir('projects'))
157
 
158
  # Chat Interface
@@ -179,11 +214,29 @@ if st.button("Format & Lint"):
179
 
180
  # AI-Infused Tools
181
  st.header("AI-Powered Tools")
 
 
 
182
  text_to_summarize = st.text_area("Enter text to summarize:")
183
  if st.button("Summarize"):
184
  summary = summarize_text(text_to_summarize)
185
  st.write(f"Summary: {summary}")
186
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
  # Code Generation
188
  st.header("Code Generation")
189
  code_idea = st.text_input("Enter your code idea:")
@@ -194,11 +247,16 @@ if st.button("Generate Code"):
194
  except Exception as e:
195
  st.error(f"Error generating code: {e}")
196
 
197
- # Launch Chat App
198
  if st.button("Launch Chat App"):
199
  # Get the current working directory
200
  cwd = os.getcwd()
201
 
 
 
 
 
 
202
  # Construct the command to launch the chat app
203
  command = f"cd projects/{project_name} && streamlit run chat_app.py"
204
 
 
3
  import subprocess
4
  import random
5
  import string
6
+ from huggingface_hub import cached_download, hf_hub_url, hf_hub_token
7
  from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
8
  import black
9
  import pylint
10
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
11
+ from transformers import pipeline
12
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
13
 
14
  # Define functions for each feature
15
 
 
151
 
152
  return generated_code
153
 
154
+ # 7. Sentiment Analysis
155
+ def analyze_sentiment(text):
156
+ """Analyzes the sentiment of a given text.
157
+
158
+ Args:
159
+ text: The text to analyze.
160
+
161
+ Returns:
162
+ A dictionary containing the sentiment label and score.
163
+ """
164
+ model_name = 'distilbert-base-uncased-finetuned-sst-3-literal-labels'
165
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
166
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
167
+ classifier = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
168
+ result = classifier(text)[0]
169
+ return result
170
+
171
+ # 8. Text Translation
172
+ def translate_text(text, target_language):
173
+ """Translates a given text to the specified target language.
174
+
175
+ Args:
176
+ text: The text to translate.
177
+ target_language: The target language code (e.g., 'fr' for French, 'es' for Spanish).
178
+
179
+ Returns:
180
+ The translated text.
181
+ """
182
+ translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-es") # Example: English to Spanish
183
+ translation = translator(text, target_lang=target_language)[0]['translation_text']
184
+ return translation
185
+
186
  # Streamlit App
187
  st.title("CodeCraft: Your AI-Powered Development Toolkit")
188
 
189
  # Workspace Selection
190
+ st.sidebar.header("Select Workspace")
191
  project_name = st.sidebar.selectbox("Choose a project", os.listdir('projects'))
192
 
193
  # Chat Interface
 
214
 
215
  # AI-Infused Tools
216
  st.header("AI-Powered Tools")
217
+
218
+ # Text Summarization
219
+ st.subheader("Text Summarization")
220
  text_to_summarize = st.text_area("Enter text to summarize:")
221
  if st.button("Summarize"):
222
  summary = summarize_text(text_to_summarize)
223
  st.write(f"Summary: {summary}")
224
 
225
+ # Sentiment Analysis
226
+ st.subheader("Sentiment Analysis")
227
+ text_to_analyze = st.text_area("Enter text to analyze sentiment:")
228
+ if st.button("Analyze Sentiment"):
229
+ sentiment_result = analyze_sentiment(text_to_analyze)
230
+ st.write(f"Sentiment: {sentiment_result['label']}, Score: {sentiment_result['score']}")
231
+
232
+ # Text Translation
233
+ st.subheader("Text Translation")
234
+ text_to_translate = st.text_area("Enter text to translate:")
235
+ target_language = st.selectbox("Choose target language", ['fr', 'es', 'de', 'zh-CN']) # Example languages
236
+ if st.button("Translate"):
237
+ translation = translate_text(text_to_translate, target_language)
238
+ st.write(f"Translation: {translation}")
239
+
240
  # Code Generation
241
  st.header("Code Generation")
242
  code_idea = st.text_input("Enter your code idea:")
 
247
  except Exception as e:
248
  st.error(f"Error generating code: {e}")
249
 
250
+ # Launch Chat App (with Authentication)
251
  if st.button("Launch Chat App"):
252
  # Get the current working directory
253
  cwd = os.getcwd()
254
 
255
+ # User Authentication
256
+ hf_token = st.text_input("Enter your Hugging Face Token:")
257
+ if hf_token:
258
+ hf_hub_token(hf_token)
259
+
260
  # Construct the command to launch the chat app
261
  command = f"cd projects/{project_name} && streamlit run chat_app.py"
262