Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import assemblyai as aai
|
| 3 |
import librosa
|
|
@@ -145,12 +155,10 @@ def export_file(format_type, state):
|
|
| 145 |
path = f"/tmp/conversation_{timestamp}.txt"
|
| 146 |
with open(path, "w", encoding="utf-8") as f:
|
| 147 |
f.write(conversation)
|
| 148 |
-
|
| 149 |
elif format_type == "JSON":
|
| 150 |
path = f"/tmp/conversation_{timestamp}.json"
|
| 151 |
with open(path, "w", encoding="utf-8") as f:
|
| 152 |
json.dump(segments, f, indent=4)
|
| 153 |
-
|
| 154 |
elif format_type == "CSV":
|
| 155 |
path = f"/tmp/conversation_{timestamp}.csv"
|
| 156 |
with open(path, "w", newline="", encoding="utf-8") as f:
|
|
@@ -159,21 +167,18 @@ def export_file(format_type, state):
|
|
| 159 |
)
|
| 160 |
writer.writeheader()
|
| 161 |
writer.writerows(segments)
|
| 162 |
-
|
| 163 |
elif format_type == "WORD":
|
| 164 |
path = f"/tmp/conversation_{timestamp}.docx"
|
| 165 |
doc = Document()
|
| 166 |
doc.add_heading("Conversation Transcript", 0)
|
| 167 |
doc.add_paragraph(conversation)
|
| 168 |
doc.save(path)
|
| 169 |
-
|
| 170 |
elif format_type == "PDF":
|
| 171 |
path = f"/tmp/conversation_{timestamp}.pdf"
|
| 172 |
doc = SimpleDocTemplate(path)
|
| 173 |
styles = getSampleStyleSheet()
|
| 174 |
content = [Paragraph(conversation.replace("\n", "<br/>"), styles["Normal"])]
|
| 175 |
doc.build(content)
|
| 176 |
-
|
| 177 |
else:
|
| 178 |
return None
|
| 179 |
|
|
|
|
| 1 |
+
# Patch missing HfFolder before gradio imports it
|
| 2 |
+
import sys
|
| 3 |
+
from unittest.mock import MagicMock
|
| 4 |
+
try:
|
| 5 |
+
from huggingface_hub import HfFolder
|
| 6 |
+
except ImportError:
|
| 7 |
+
import huggingface_hub
|
| 8 |
+
huggingface_hub.HfFolder = MagicMock()
|
| 9 |
+
sys.modules["huggingface_hub"].HfFolder = MagicMock()
|
| 10 |
+
|
| 11 |
import gradio as gr
|
| 12 |
import assemblyai as aai
|
| 13 |
import librosa
|
|
|
|
| 155 |
path = f"/tmp/conversation_{timestamp}.txt"
|
| 156 |
with open(path, "w", encoding="utf-8") as f:
|
| 157 |
f.write(conversation)
|
|
|
|
| 158 |
elif format_type == "JSON":
|
| 159 |
path = f"/tmp/conversation_{timestamp}.json"
|
| 160 |
with open(path, "w", encoding="utf-8") as f:
|
| 161 |
json.dump(segments, f, indent=4)
|
|
|
|
| 162 |
elif format_type == "CSV":
|
| 163 |
path = f"/tmp/conversation_{timestamp}.csv"
|
| 164 |
with open(path, "w", newline="", encoding="utf-8") as f:
|
|
|
|
| 167 |
)
|
| 168 |
writer.writeheader()
|
| 169 |
writer.writerows(segments)
|
|
|
|
| 170 |
elif format_type == "WORD":
|
| 171 |
path = f"/tmp/conversation_{timestamp}.docx"
|
| 172 |
doc = Document()
|
| 173 |
doc.add_heading("Conversation Transcript", 0)
|
| 174 |
doc.add_paragraph(conversation)
|
| 175 |
doc.save(path)
|
|
|
|
| 176 |
elif format_type == "PDF":
|
| 177 |
path = f"/tmp/conversation_{timestamp}.pdf"
|
| 178 |
doc = SimpleDocTemplate(path)
|
| 179 |
styles = getSampleStyleSheet()
|
| 180 |
content = [Paragraph(conversation.replace("\n", "<br/>"), styles["Normal"])]
|
| 181 |
doc.build(content)
|
|
|
|
| 182 |
else:
|
| 183 |
return None
|
| 184 |
|