在阿里云上用chatgpt 10分钟生了一个chatgpt本地部署方案

之前玩完llama.cpp后,发现很好用,就想着加上一个web界面。

但是本人对于前端非常不懂,就想着用ai自己来做一个。

于是问了chatgpt,大概耗时10分钟就跑完了前端和后端,你别说还像个样子

我的问题:

想做一个基于python,实现类似chatgpt的风格的网页。1.用户输入提示词;2.后台调用shell命令3.将shell命令的结果展示到网页上

chagpt的返回的代码

要创建一个类似于ChatGPT风格的网页,您可以使用Python的Web框架Flask和后端库如subprocess来调用shell命令。以下是一个简单的示例:

  1. 安装Flask库:
bashCopy codepip install Flask
  1. 创建一个名为app.py的文件,然后添加以下代码:
pythonCopy codefrom flask import Flask, render_template, request
import subprocess

app = Flask(__name__)

@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'POST':
        user_input = request.form['prompt']
        result = run_shell_command(user_input)
        return render_template('index.html', result=result)
    return render_template('index.html', result=None)

def run_shell_command(command):
    process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    output, error = process.communicate()
    if error:
        return error.decode('utf-8')
    return output.decode('utf-8')

if __name__ == '__main__':
    app.run(debug=True)
  1. 创建一个名为templates的文件夹,并在其中创建一个名为index.html的文件。将以下代码添加到index.html:
htmlCopy code


    
    
    Python ChatGPT-like Web App


    

Python ChatGPT-like Web App

{% if result %}

Result:

{{ result }}
{% endif %}
  1. 运行app.py文件启动Web应用:
bashCopy codepython app.py

现在,您可以访问http://127.0.0.1:5000/以查看您的基于Python的类似于ChatGPT风格的网页。在输入框中输入提示词,然后单击提交按钮,它将调用shell命令并将结果显示在网页上。

请注意,该示例允许用户执行任意shell命令,可能存在安全风险。在实际部署中,您需要对用户输入进行严格的验证以防止潜在的安全问题。

展开阅读全文

页面更新:2024-03-02

标签:阿里   示例   安全问题   文件夹   命令   提示   风格   代码   网页   文件   方案   用户

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2008-2024 All Rights Reserved. Powered By bs178.com 闽ICP备11008920号-3
闽公网安备35020302034844号

Top