Richie-O3 commited on
Commit
c380b7b
1 Parent(s): 15ca86d

add export csv functionality

Browse files
Files changed (2) hide show
  1. app.py +13 -27
  2. backend_functions.py +4 -2
app.py CHANGED
@@ -38,34 +38,11 @@ with gr.Blocks() as main_app:
38
  "Context Prompt", "Final Response GPT", "Create Clean Message", "Create Audio Elevenlabs", "Create Video D-iD", "Final Time"]
39
  table_times = gr.DataFrame(headers=columns, visible=False, interactive=False)
40
 
41
- export_button = gr.Button(value="Export CSV")
42
-
43
-
44
-
45
- # with gr.Tab('Ventana Pruebas'):
46
- # with gr.Row():
47
- # with gr.Column():
48
- # button_show = gr.Button(value="Mostrar texto")
49
- # with gr.Column():
50
- # button_hidden = gr.Button(value="Ocultar texto")
51
-
52
- # with gr.Row(visible=False) as first_row:
53
- # text = gr.Textbox(value="Hola mundo")
54
-
55
 
56
- # Actions
57
-
58
- # button_show.click(
59
- # fn=make_visible,
60
- # inputs=None,
61
- # outputs=first_row
62
- # )
63
-
64
- # button_hidden.click(
65
- # fn=make_invisible,
66
- # inputs=None,
67
- # outputs=first_row
68
- # )
69
 
70
  text.submit(
71
  fn=get_answer,
@@ -73,6 +50,10 @@ with gr.Blocks() as main_app:
73
  outputs=[chat, output_audio, output_video, table_times]
74
  ).then(
75
  lambda: None, None, [text]
 
 
 
 
76
  )
77
 
78
  button_text.click(
@@ -81,11 +62,16 @@ with gr.Blocks() as main_app:
81
  outputs=[chat, output_audio, output_video, table_times]
82
  ).then(
83
  lambda: None, None, [text]
 
 
 
 
84
  )
85
 
86
  export_button.click(
87
  fn=export_dataframe,
88
  inputs=table_times,
 
89
  )
90
 
91
  main_app.load(init_greeting, inputs=[chat, messages], outputs=[chat, messages])
 
38
  "Context Prompt", "Final Response GPT", "Create Clean Message", "Create Audio Elevenlabs", "Create Video D-iD", "Final Time"]
39
  table_times = gr.DataFrame(headers=columns, visible=False, interactive=False)
40
 
41
+ with gr.Column():
42
+ with gr.Row(visible=False) as row_export_csv:
43
+ export_button = gr.Button(value="Export CSV")
44
+ csv = gr.File(interactive=False, visible=False)
 
 
 
 
 
 
 
 
 
 
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
  text.submit(
48
  fn=get_answer,
 
50
  outputs=[chat, output_audio, output_video, table_times]
51
  ).then(
52
  lambda: None, None, [text]
53
+ ).then(
54
+ fn=make_visible,
55
+ inputs=None,
56
+ outputs=row_export_csv
57
  )
58
 
59
  button_text.click(
 
62
  outputs=[chat, output_audio, output_video, table_times]
63
  ).then(
64
  lambda: None, None, [text]
65
+ ).then(
66
+ fn=make_visible,
67
+ inputs=None,
68
+ outputs=row_export_csv
69
  )
70
 
71
  export_button.click(
72
  fn=export_dataframe,
73
  inputs=table_times,
74
+ outputs=csv
75
  )
76
 
77
  main_app.load(init_greeting, inputs=[chat, messages], outputs=[chat, messages])
backend_functions.py CHANGED
@@ -8,13 +8,13 @@ from pinecone import Pinecone
8
  import uuid
9
  import re
10
  import pandas as pd
11
- import tensorflow as tf
12
  from google.cloud import storage
13
  from elevenlabs.client import ElevenLabs, AsyncElevenLabs
14
  from elevenlabs import play, save, Voice, stream
15
  from pymongo.mongo_client import MongoClient
16
  from utils import create_folders
17
  from gcp import download_credentials
 
18
  from dotenv import load_dotenv
19
  load_dotenv()
20
 
@@ -382,4 +382,6 @@ def init_greeting(chatbot, history_messages):
382
  def export_dataframe(df):
383
  final_df = pd.DataFrame(df)
384
  final_df = final_df.iloc[1:]
385
- final_df.to_csv("./csv_times/csv_times.csv", index=False, encoding='utf-8')
 
 
 
8
  import uuid
9
  import re
10
  import pandas as pd
 
11
  from google.cloud import storage
12
  from elevenlabs.client import ElevenLabs, AsyncElevenLabs
13
  from elevenlabs import play, save, Voice, stream
14
  from pymongo.mongo_client import MongoClient
15
  from utils import create_folders
16
  from gcp import download_credentials
17
+ from csv import writer
18
  from dotenv import load_dotenv
19
  load_dotenv()
20
 
 
382
  def export_dataframe(df):
383
  final_df = pd.DataFrame(df)
384
  final_df = final_df.iloc[1:]
385
+ final_df.to_csv("./csv_times/csv_times.csv", index=False, encoding='utf-8')
386
+
387
+ return gr.File(value="./csv_times/csv_times.csv", visible=True)