
使用 Whisper API 通过设备麦克风把语音转录为文本
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == '__main__':
app.run()
import requests
response = requests.get('https://api.github.com')
print(response.status_code)
print(response.json())
from sqlalchemy import create_engine, Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
Base = declarative_base()
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
name = Column(String)
engine = create_engine('sqlite:///:memory:')
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
session = Session()
new_user = User(name='Alice')
session.add(new_user)
session.commit()
users = session.query(User).all()
for user in users:
print(user.name)
import pandas as pd
df = pd.DataFrame({
'A': [1, 2, 3],
'B': ['a', 'b', 'c']
})
print(df)
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
iris = load_iris()
X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.2)
clf = KNeighborsClassifier()
clf.fit(X_train, y_train)
print(clf.score(X_test, y_test))
from PIL import Image
img = Image.open('example.jpg')
gray_img = img.convert('L') # 转换为灰度图像
gray_img.show()
import spacy
nlp = spacy.load("en_core_web_sm")
doc = nlp("Apple is looking at buying U.K. startup for $1 billion")
for ent in doc.ents:
print(ent.text, ent.label_)
import click
@click.command()
@click.option('--count', default=1, help='Number of greetings.')
@click.argument('name')
def hello(count, name):
for _ in range(count):
click.echo(f"Hello {name}!")
if __name__ == '__main__':
hello()
import asyncio
async def main():
print('Hello')
await asyncio.sleep(1)
print('World')
asyncio.run(main())
# test_example.py
def add(a, b):
return a + b
def test_add():
assert add(1, 2) == 3
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
logger.info('This is an info message')
每一次互动,皆是鼓励, 每一份支持,共促成长。