calibr234 commited on
Commit
cf4e040
·
verified ·
1 Parent(s): db201c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -56
app.py CHANGED
@@ -8,66 +8,66 @@ import sys
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:
 
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: