软件工程课程第一次个人作业

🧙‍♂️ 软工生存指南:

从“代码小白”到“AI魔法师”的第一次作业

这个作业属于哪个课程 2026-01软件工程与软件工程实践
这个作业要求在哪里 软件工程课程第一次个人作业
这个作业的目标 熟悉Markdown排版、GitHub与博客园使用;梳理个人技能树;实践AI辅助学习及Hugging Face API调用,并具备初步的前后端交互工程思维
学号 102402107

摘要:这是一份带点欢乐的《软件工程》第一次个人作业记录。包含我的硬核技能树剖析、对AI学习指南的吐槽、以及一次“惊心动魄”的Hugging Face API调用实战。准备好了吗?出发!

🛠️ 第一部分:准备工作(兵马未动,粮草先行)

在开启这段软工之旅前,我按照要求完成了以下“打卡”任务。

① GitHub

注册并完善了个人信息,GitHub 就是我未来的代码后花园!

🔗 我的 GitHub 主页:https://github.com/cccch412

📸 【GitHub 主页搭建截图】

GitHub主页截图

② 博客园

  • 注册并完善了个人资料(换上了帅气的头像),设置了博客样式。
  • 已关注任课老师 黄兆武,以及助教 李怡涵焦圣蒙 的博客。
  • 已成功加入博客园班级 H202601软件工程与软件工程实践,并且确认已实名制。

📸 【博客园个人主页截图】

博客园个人主页截图

📝 第二部分:灵魂拷问——我的技能树与学习期望

1. 当前技能树与技术偏好(自我评估)

作为一个正在努力摆脱“只会写Hello World”标签的准开发者:
🌳 我的技能树

陈瑀涵的技能树
├── 💻 已掌握(能独立完成小型程序)
│   ├── Java        ████████░░ 
│   ├── C++         ████████░░ 
│   ├── Python      ████████░░ 
│   ├── MySQL       █████░░░░░ 
│   └── HTML/CSS/JS ████░░░░░░ 
│
├── 🎯 感兴趣方向
│   ├── 后端开发(Spring Boot 生态)
│   ├── 云计算
│   └── 大模型应用开发
│
└── 📌 待补短板
    ├── Git 多人协作(冲突处理头疼中)
    ├── 工程化思维(需求分析 & 架构设计)
    └── 测试与部署(单元测试 & 云服务器)
  • 我会什么(能力A、B、C):
    • 能力A:熟练掌握 Java,c++,python 语言,能独立完成面向对象的小型程序编写。
    • 能力B:掌握 MySQL 基础,能写出基本的增删改查(CRUD)SQL语句。
    • 能力C:了解 HTML/CSS/JavaScript 基础,能写简单的静态页面。
  • 我对什么感兴趣:
    • 后端开发(特别是 Spring Boot 生态)、云计算以及最近大火的大模型应用开发。
  • 我不会什么(重点反思):
    • 团队协作:不会熟练使用 Git 进行多人协作,只会 git pushgit pull,遇到冲突就头大。
    • 工程化思维:缺乏大型项目的架构设计经验,不知道如何做需求分析和系统设计。
    • 测试与部署:不会写单元测试,不知道怎么把项目部署到云服务器上。

2. 代码量与“小目标”

  • 截至目前:我大概写了 3000+ 行代码(包括各种课程作业和练习)。
  • 本学期期望:希望经过《软件工程》的洗礼,代码量能突破 8000+ 行,并且其中至少有 2000 行是高质量的、有测试覆盖的代码!

3. 课程期待与收获

  • 最期待学习:如何把一团乱麻的需求,变成清晰的 UML 图和优雅的代码设计。
  • 期望收获:希望能真正体验一次“软件开发生命周期”,学会用团队的力量去交付一个真实的项目,而不是单打独斗。

🤖 第三部分:AI参谋——软件工程学习指南(及我的吐槽)

为了更好规划学习路径,我召唤了AI助手(DeepSeek),让它生成了以下学习指南:

[AI生成的学习指南]

  1. 基础理论夯实:重点掌握软件生命周期模型(瀑布、敏捷)、需求工程、软件设计模式。
  2. 工具链熟悉:熟练使用 Git 进行版本控制,掌握 UML 建模工具(如 StarUML),熟悉项目管理工具(如 Jira)。
  3. 实践出真知:参与一个完整的团队项目,从需求分析到测试部署,亲身体验每个环节。
  4. 代码规范:遵循 Google 或阿里代码规范,养成写注释和文档的好习惯。
  5. 测试驱动:学习 JUnit 等测试框架,尝试先写测试再写代码(TDD)。

【我的分析与感悟】

  • 合理性:这份指南大方向非常正确,特别是“实践出真知”和“测试驱动”这两点,确实是我目前的短板。
  • 对我有帮助吗?:非常有帮助。它帮我理清了学习路线。不过,我觉得“TDD”对初学者来说可能有点反直觉(谁会先写测试再写代码啊!),我会先从写代码后补测试开始,逐步适应。
  • 结论:AI是个好参谋,但最终还是要靠自己一行一行敲代码去实践。

🎨 第四部分:硬核实操——Hugging Face API 图像生成之旅

这是本次作业的重头戏!

要求:注册Hugging Face,获取API,调用 XLabs-AI/flux-RealismLora 模型,并结合前端界面实现交互生成。

🪜 操作步骤记录

  1. 账号与API获取:在 Hugging Face官网 注册账号,并在 Settings -> Access Tokens 中创建了一个拥有 Read 权限的 Token。
  2. 模型探索:找到了模型地址 XLabs-AI/flux-RealismLora。这个模型以生成极其逼真的图像而闻名。
  3. 后端代码编写:使用 Python 编写调用脚本(代码如下)。
  4. 前端交互界面:使用简单的 HTML 搭建了一个带有输入框和图片展示区的页面,实现前后端联动。

💡 提示词设计思路与修改过程

在本次实践中,我通过三次迭代逐步优化了提示词,从最初的简单描述,到加入环境细节,再到强化摄影参数和规避AI常见的“塑料感”,最终得到了满意的结果。

🔹 第一次提示词:初步尝试

Prompt: At the entrance of a convenience store in the city at night, several young people, night scene, photorealistic photo

第一次生成

分析: 这是最基础的描述,只交代了地点、人物和夜景,但是生成的人物没有正脸。

🔹 第二次提示词:增加环境细节与真实感

Prompt: Ultra-realistic urban street group portrait photography, 10 p.m. in summer, real life scene at the gate of a convenience store. 3 to 4 young people chat and interact briefly at the entrance of the convenience store. Some hold drinks in their hands, some sit on plastic outdoor chairs at the door, some look down at mobile phones. Strong bright white light comes through the glass door and French window of the convenience store. The street is mixed with warm yellow street lamps and halo of car lights in the distance. The characters wear ordinary daily clothes: T-shirts, shirts, shorts, jeans, sneakers, no internet celebrity style or deliberate dressing. The expressions, standing postures and interactions of characters must be like real passers-by, not overly refined or posed. The environment contains plenty of real convenience store details: freezer stickers, promotional posters, trash cans, door mats, glass reflections, shared bikes on the roadside, water marks left by beverage bottles on the ground. The whole picture is like a life snapshot accidentally captured by a city photographer. Key points to show: natural multi-person interaction, night convenience store lighting atmosphere, glass reflection effect, real life sense of ordinary people, cinematic street photography, ultra-realistic, natural skin texture, real environmental texture, documentary photography style.

第二次生成

分析: 这一版提示词非常详细,不仅规定了时间(晚上10点)、人物动作(喝饮料、坐塑料椅、看手机)、灯光(便利店冷白光+路灯暖黄光),还特别强调了“不要网红风”、“要有生活痕迹”(如地面水渍、共享单车)。但是生成的人物面部会不自然。

🔹 第三次提示词:强化摄影参数与负面约束

Prompt: Night street photography, 10 PM summer, convenience store with clear store sign above entrance, bright cool white fluorescent light inside, warm yellow street ambient light. Four young asian people, natural relaxed casual poses, soft body language, not stiff, 1 young man standing at door, three young girls, one girl sits on plastic chair, all casually chatting, holding bottled water. Realistic asian faces, skin pores, natural skin texture, natural eye catchlights. Glass door, posters, trash cans, bicycle outside. Shot on Sony A7III, 35mm f/2, candid documentary snapshot, subtle film grain, natural depth of field, photorealistic, 8k, sharp faces. Avoid stiff pose, rigid limbs, unnatural body, bad anatomy, plastic skin, doll face, deformed hands, distorted fingers, disfigured, cartoon, render.

第三次生成

分析: 最终版加入了具体的相机型号(Sony A7III)和镜头参数(35mm f/2),并明确指出了要规避的负面特征(如塑料皮肤、畸形手指、僵硬姿势)。同时将人物设定为亚洲面孔。但是生成到最后我还是更喜欢第一次生成的那张,更真实一点,后面两张的AI感太重了。


💻 核心调用代码展示

以下是通过 Hugging Face API 调用 XLabs-AI/flux-RealismLora 模型生成图像的核心 Python 代码:

from flask import Flask, render_template, request
import os
import time
from huggingface_hub import InferenceClient
from PIL import Image
app = Flask(__name__)
HF_TOKEN = "hf_"
client = InferenceClient(
    model="black-forest-labs/FLUX.1-dev",
    token=HF_TOKEN,
)
def query(payload):
    try:
        os.makedirs("static", exist_ok=True)
        prompt = payload.get("inputs", "")
        params = payload.get("parameters", {})
        print(f"提示词: {prompt[:50]}...")
        print("生成中,请稍候...")
        result = client.text_to_image(
            prompt=prompt,
            num_inference_steps=params.get("num_inference_steps", 28),
            guidance_scale=params.get("guidance_scale", 3.5),
        )
        timestamp = int(time.time())
        filename = f"output_{timestamp}.png"
        img_path = os.path.join("static", filename)
        if isinstance(result, Image.Image):
            result.save(img_path)
            print(f"图像保存成功: {img_path}")
            return filename
        else:
            print("返回类型不是图片")
            return None
    except Exception as e:
        print(f"请求异常: {str(e)}")
        return None
@app.route('/', methods=["GET", "POST"])
def index():
    img_path = None
    prompt = ""
    if request.method == "POST":
        prompt = request.form.get("prompt", "").strip()
        if prompt:
            payload = {
                "inputs": prompt,
                "parameters": {
                    "num_inference_steps": 28,
                    "guidance_scale": 3.5
                }
            }
            img_path = query(payload)
    return render_template("index.html", img_path=img_path, prompt=prompt)


if __name__ == '__main__':
    os.makedirs("static", exist_ok=True)
    print("Flask 应用启动中...")
    print("访问地址: http://127.0.0.1:5000")
    app.run(debug=True, host='0.0.0.0', port=5000)

🖥️ 前端交互页面实现

为了实现交互式生成,我搭建了一个简单的 HTML 前端页面,包含提示词输入框、生成按钮和图像展示区。

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>Flux RealismLora 图像生成</title>
</head>
<body>
    <h2>写实图像生成器(HuggingFace Flux API)</h2>
    <form method="post">
        <h4>请输入提示词:</h4>
        <textarea name="prompt" rows="4" cols="70">{{ prompt }}</textarea>
        <br><br>
        <button type="submit">提交生成图片</button>
    </form>

    {% if img_path %}
        <h3>生成结果:</h3>
        <img src="{{ img_path }}" width="750">
    {% endif %}
</body>
</html>
交互页面截图

📚 附录

附加后台博文编辑页面的截图

后台博文编辑页面截图
posted @ 2026-09-10 23:53  陈瑀涵  阅读(31)  评论(0)    收藏  举报