admin管理员组文章数量:1635664
https://huggingface.co/spaces
首先现在这个spaces里面创建自己的空间,相当于小型服务器
创建的时候:
- 选择免费的服务器硬件,
- SDK普通运行py程序的花选择Gradio就行,这个里面东西最少,其他三个里面都会有一些模版。
- License选择第一个apache2.0即可。
创建完之后到达这页面(也就是自己的服务器页面了):
这个默认服务器运行app.py文件。是通过README.md文件里面的
app_file: app.py
设置的,
通过在app.py中写代码:
from langchain.chat_models import ChatOpenAI
from langchain.schema import AIMessage, HumanMessage
import gradio as gr
import os
# os.environ["OPENAI_API_KEY"] = "sk-Bwuah7JrCpPug7HGdS3nUGh3TAOuSgAvBvnw8CVVyL5lTgT" # Replace with your key
client = ChatOpenAI(temperature=1.0, model='gpt-3.5-turbo-0613', base_url='https://api.chatanywhere.tech/v1')
def predict(message, history):
history_langchain_format = []
for human, ai in history:
history_langchain_format.append(HumanMessage(content=human))
history_langchain_format.append(AIMessage(content=ai))
# Check if it's the first interaction
if len(history_langchain_format) == 0:
history_langchain_format.append(HumanMessage(content="下面请用中文回答我的问题!"))#界面看不到的消息,用于让机器预加载一些对话信息
history_langchain_format.append(HumanMessage(content=message))
gpt_response = client(history_langchain_format)
return gpt_response.content
gr.ChatInterface(predict,description="下面与小兔兔机器人进行对话",
theme="compact").launch()
这时候代码有了,但是缺少python里面import的一些库环境,还需要下载这些库,创建requirements.txt文件默认下载,系统会在修改完文件后,自动重启服务器并下载requirements里面的库,只需下载一次。 如下所示:
弄完后,点击app:
即可跳到app页面:
这个就可以用外部链接访问啦!!!
下面这个网址可以免费获取chatgptAPI,但是免费版每天只有100条对话。
GitHub - chatanywhere/GPT_API_free: Free ChatGPT API Key,免费ChatGPT API,支持GPT4 API(免费),ChatGPT国内可用免费转发API,直连无需代理。可以搭配ChatBox等软件/插件使用,极大降低接口使用成本。国内即可无限制畅快聊天。
tips1:使用的时候需要加 上base_url
client = ChatOpenAI(temperature=1.0, model='gpt-3.5-turbo-0613', base_url='https://api.chatanywhere')
也就是base_url='https://api.chatanywhere',不然不能使用。
tips2:需要加上
(base) jie@dell:~/桌面$ unset all_proxy; unset ALL_PROXY
下面当使用“”袋里“”提示ip有问题的时候。
python利用gradio快速创建页面及程序:
Quickstart
版权声明:本文标题:如何在https:huggingface.cospaces中创建自己的远程服务器并部署AI相关项目并利用gradio创建界面(获取免费chatgpt的API_key) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1729213658a1190177.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论