Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,75 +3,75 @@ import pandas as pd
|
|
| 3 |
import os
|
| 4 |
import subprocess
|
| 5 |
import sys
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
"""
|
| 76 |
Tweet Processing Script for Google Colab - Enhanced with NLP and Sentiment Analysis
|
| 77 |
This version is optimized for Google Colab with GPU acceleration and Google Drive integration.
|
|
@@ -882,5 +882,5 @@ if __name__ == "__main__":
|
|
| 882 |
|
| 883 |
# Run the main function
|
| 884 |
main(reset_checkpoint=reset_checkpoint, input_file=input_file) )
|
| 885 |
-
|
| 886 |
-
|
|
|
|
| 3 |
import os
|
| 4 |
import subprocess
|
| 5 |
import sys
|
| 6 |
+
|
| 7 |
+
# Install spaCy model
|
| 8 |
+
os.system("python -m spacy download en_core_web_sm")
|
| 9 |
+
|
| 10 |
+
def process_tweets(files, reset_processing=False):
|
| 11 |
+
# Save uploaded files
|
| 12 |
+
file_paths = []
|
| 13 |
+
for file in files:
|
| 14 |
+
if file.name.endswith('.csv'):
|
| 15 |
+
# Ensure directory exists
|
| 16 |
+
os.makedirs("projects_twitter_post", exist_ok=True)
|
| 17 |
+
|
| 18 |
+
# Save file to the directory
|
| 19 |
+
dest_path = f"projects_twitter_post/{os.path.basename(file.name)}"
|
| 20 |
+
os.system(f"cp {file.name} {dest_path}")
|
| 21 |
+
file_paths.append(dest_path)
|
| 22 |
+
|
| 23 |
+
if not file_paths:
|
| 24 |
+
return "No CSV files uploaded. Please upload CSV files containing tweet data."
|
| 25 |
+
|
| 26 |
+
# Run the processing script
|
| 27 |
+
reset_flag = "--reset" if reset_processing else ""
|
| 28 |
+
result = subprocess.run(
|
| 29 |
+
f"python process_tweet_huggingface.py {reset_flag}",
|
| 30 |
+
shell=True,
|
| 31 |
+
capture_output=True,
|
| 32 |
+
text=True
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# Check if output files were created
|
| 36 |
+
output_files = []
|
| 37 |
+
for file_path in file_paths:
|
| 38 |
+
base_name = os.path.basename(file_path).replace('.csv', '')
|
| 39 |
+
processed_path = f"projects_twitter_post/{base_name}_processed.csv"
|
| 40 |
+
analysis_path = f"projects_twitter_post/{base_name}_analysis.csv"
|
| 41 |
+
|
| 42 |
+
if os.path.exists(processed_path):
|
| 43 |
+
output_files.append(processed_path)
|
| 44 |
+
if os.path.exists(analysis_path):
|
| 45 |
+
output_files.append(analysis_path)
|
| 46 |
+
|
| 47 |
+
return_files = [f for f in output_files if os.path.exists(f)]
|
| 48 |
+
|
| 49 |
+
log_output = result.stdout + "\n" + result.stderr
|
| 50 |
+
|
| 51 |
+
return log_output, return_files
|
| 52 |
+
|
| 53 |
+
with gr.Blocks() as demo:
|
| 54 |
+
gr.Markdown("# Crypto Tweet Processor")
|
| 55 |
+
gr.Markdown("Upload CSV files containing tweet data to process")
|
| 56 |
+
|
| 57 |
+
with gr.Row():
|
| 58 |
+
files_input = gr.File(file_count="multiple", label="Upload CSV Files")
|
| 59 |
+
reset_checkbox = gr.Checkbox(label="Reset Processing", value=False)
|
| 60 |
+
|
| 61 |
+
process_btn = gr.Button("Process Tweets")
|
| 62 |
+
|
| 63 |
+
output_text = gr.Textbox(label="Processing Log")
|
| 64 |
+
output_files = gr.File(label="Processed Files", file_count="multiple")
|
| 65 |
+
|
| 66 |
+
process_btn.click(
|
| 67 |
+
process_tweets,
|
| 68 |
+
inputs=[files_input, reset_checkbox],
|
| 69 |
+
outputs=[output_text, output_files]
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
# Add the modified processing script code here
|
| 73 |
+
with open("process_tweet_huggingface.py", "w") as f:
|
| 74 |
+
f.write(#!/usr/bin/env python3
|
| 75 |
"""
|
| 76 |
Tweet Processing Script for Google Colab - Enhanced with NLP and Sentiment Analysis
|
| 77 |
This version is optimized for Google Colab with GPU acceleration and Google Drive integration.
|
|
|
|
| 882 |
|
| 883 |
# Run the main function
|
| 884 |
main(reset_checkpoint=reset_checkpoint, input_file=input_file) )
|
| 885 |
+
|
| 886 |
+
demo.launch()
|