|
import gradio as gr |
|
from transformers import pipeline |
|
import numpy as np |
|
|
|
transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base.en") |
|
|
|
def transcribe(stream, new_chunk): |
|
sr, y = new_chunk |
|
y = y.astype(np.float32) |
|
y /= np.max(np.abs(y)) |
|
|
|
if stream is not None: |
|
stream = np.concatenate([stream, y]) |
|
else: |
|
stream = y |
|
return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"] |
|
|
|
|
|
demo = gr.Interface( |
|
transcribe, |
|
["state", gr.Audio(sources=["microphone"], streaming=True)], |
|
["state", "text"], |
|
live=True, |
|
) |
|
|
|
demo.launch() |
|
|
|
|
|
|
|
|
|
|
|
import base64 |
|
import pandas as pd |
|
|
|
|
|
data = {'Column1': [1, 2], 'Column2': [3, 4]} |
|
df = pd.DataFrame(data) |
|
|
|
|
|
def to_base64_csv(df): |
|
csv = df.to_csv(index=False) |
|
b64 = base64.b64encode(csv.encode()).decode() |
|
return f"data:text/csv;base64,{b64}" |
|
|
|
|
|
def to_base64_txt(df): |
|
txt = df.to_csv(index=False, sep='\t') |
|
b64 = base64.b64encode(txt.encode()).decode() |
|
return f"data:text/plain;base64,{b64}" |
|
|
|
|
|
csv_link = to_base64_csv(df) |
|
txt_link = to_base64_txt(df) |
|
|
|
|
|
markdown_csv_link = f"**[π₯ Download Dataset as CSV]({csv_link})**" |
|
markdown_txt_link = f"**[π₯ Download Dataset as TXT]({txt_link})**" |
|
|
|
|
|
print(markdown_csv_link) |
|
print(markdown_txt_link) |
|
|
|
|
|
|
|
|
|
import gradio as gr |
|
|
|
def process_live_input(input_stream): |
|
|
|
|
|
processed_output = some_processing_function(input_stream) |
|
return processed_output |
|
|
|
iface = gr.Interface(fn=process_live_input, |
|
inputs=gr.inputs.Video(source="webcam", streaming=True), |
|
outputs="video") |
|
|
|
iface.launch() |
|
|
|
|
|
|