Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from typing import Optional
|
| 3 |
+
from tool import HFSpeech2TextFromFile
|
| 4 |
+
|
| 5 |
+
tool = HFSpeech2TextFromFile()
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def read_and_process_file(file, token):
|
| 9 |
+
"""Reads the uploaded file and processes its content."""
|
| 10 |
+
try:
|
| 11 |
+
processed_content = tool(filepath=file.name, hf_token=token)
|
| 12 |
+
return processed_content
|
| 13 |
+
except Exception as e:
|
| 14 |
+
return f"Error: {e}"
|
| 15 |
+
|
| 16 |
+
# Gradio interface
|
| 17 |
+
iface = gr.Interface(
|
| 18 |
+
fn=read_and_process_file,
|
| 19 |
+
inputs=[gr.File(label="Upload a file"), gr.Textbox(label="Enter your huggingface API token here")],
|
| 20 |
+
outputs=gr.Textbox(label="File Content"),
|
| 21 |
+
title="File Reader",
|
| 22 |
+
description="Upload a text file and see its content."
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
# Required for Hugging Face Spaces
|
| 26 |
+
if __name__ == "__main__":
|
| 27 |
+
iface.launch()
|