liyaoshi's picture
Update app.py
5544b38 verified
raw
history blame
2.02 kB
import gradio as gr
from huggingface_hub import list_models
def hello(profile: gr.OAuthProfile | None) -> str:
# ^ expect a gr.OAuthProfile object as input to get the user's profile
# if the user is not logged in, profile will be None
if profile is None:
return "I don't know you."
return f"Hello {profile.name}"
def message(message,history,profile: gr.OAuthProfile | None,oauth_token: gr.OAuthToken | None):
if profile is None:
raise gr.Error("Please login to...")
else:
print(profile)
print(f'oauth token: {oauth_token.token}')
return f"hello {profile.name}"
def list_private_models(profile: gr.OAuthProfile | None, oauth_token: gr.OAuthToken | None) -> str:
# ^ expect a gr.OAuthToken object as input to get the user's token
# if the user is not logged in, oauth_token will be None
if oauth_token is None:
return "Please log in to list private models."
models = [
f"{model.id} ({'private' if model.private else 'public'})"
for model in list_models(author=profile.username, token=oauth_token.token)
]
return "Models:\n\n" + "\n - ".join(models) + "."
with gr.Blocks(fill_height=True) as demo:
gr.Markdown(
"# ChatGPT-4o"
"\n\nThis is GPT-4o, you can use the text and image capabilities now. More capabilities like audio and video will be rolled out iteratively in the future. Stay tuned."
)
gr.LoginButton()
gr.ChatInterface(message,multimodal=True)
# style = """
# <style>
# #chat-interface {
# height: 500px; /* 设置所需的高度,这里是 500 像素 */
# overflow-y: auto; /* 启用垂直滚动条 */
# }
# </style>
# """
# gr.Markdown(style)
# ^ add a login button to the Space
# m1 = gr.Markdown()
# m2 = gr.Markdown()
# demo.load(hello, inputs=None, outputs=m1)
# demo.load(list_private_models, inputs=None, outputs=m2)
demo.launch()