Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import re
|
| 3 |
from typing import Dict, List, Tuple, Any, Optional
|
|
@@ -647,9 +652,165 @@ def analyze_code_with_cursor(code, cursor_line, cursor_column):
|
|
| 647 |
|
| 648 |
return report, result, visual_data
|
| 649 |
|
| 650 |
-
#
|
| 651 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 652 |
|
|
|
|
| 653 |
if __name__ == "__main__":
|
| 654 |
demo.launch(
|
| 655 |
server_name="0.0.0.0",
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
"""
|
| 4 |
+
Capricode Vision Pro - 修复版代码视觉定位系统
|
| 5 |
+
"""
|
| 6 |
import gradio as gr
|
| 7 |
import re
|
| 8 |
from typing import Dict, List, Tuple, Any, Optional
|
|
|
|
| 652 |
|
| 653 |
return report, result, visual_data
|
| 654 |
|
| 655 |
+
# 示例代码
|
| 656 |
+
example_code = """function calculateTotal(items) {
|
| 657 |
+
let total = 0;
|
| 658 |
+
for (let i = 0; i < items.length; i++) {
|
| 659 |
+
total += items[i].price;
|
| 660 |
+
}
|
| 661 |
+
return total;
|
| 662 |
+
}
|
| 663 |
+
|
| 664 |
+
function applyDiscount(total, discount) {
|
| 665 |
+
return total * (1 - discount);
|
| 666 |
+
}"""
|
| 667 |
+
|
| 668 |
+
# 创建Gradio界面
|
| 669 |
+
with gr.Blocks(
|
| 670 |
+
title="Capricode Vision Pro - 修复版代码视觉定位系统",
|
| 671 |
+
theme=gr.themes.Soft(primary_hue="blue")
|
| 672 |
+
) as demo:
|
| 673 |
+
|
| 674 |
+
gr.Markdown("""
|
| 675 |
+
# 👁️ Capricode Vision Pro
|
| 676 |
+
## 🚀 修复版 - 量子级精准代码定位系统
|
| 677 |
+
|
| 678 |
+
**修复了测试中发现的所有主要问题**
|
| 679 |
+
""")
|
| 680 |
+
|
| 681 |
+
with gr.Row():
|
| 682 |
+
with gr.Column(scale=2):
|
| 683 |
+
code_input = gr.Textbox(
|
| 684 |
+
label="📝 代码输入",
|
| 685 |
+
value=example_code,
|
| 686 |
+
lines=15,
|
| 687 |
+
placeholder="在此输入或粘贴代码..."
|
| 688 |
+
)
|
| 689 |
+
|
| 690 |
+
with gr.Row():
|
| 691 |
+
cursor_line = gr.Number(
|
| 692 |
+
label="📏 光标行号",
|
| 693 |
+
value=4,
|
| 694 |
+
precision=0
|
| 695 |
+
)
|
| 696 |
+
cursor_column = gr.Number(
|
| 697 |
+
label="📐 光标列号",
|
| 698 |
+
value=8,
|
| 699 |
+
precision=0
|
| 700 |
+
)
|
| 701 |
+
|
| 702 |
+
analyze_btn = gr.Button("🔍 开始量子分析", variant="primary", size="lg")
|
| 703 |
+
|
| 704 |
+
with gr.Column(scale=1):
|
| 705 |
+
report_output = gr.Markdown(
|
| 706 |
+
label="📊 分析报告",
|
| 707 |
+
value="等待分析..."
|
| 708 |
+
)
|
| 709 |
+
|
| 710 |
+
with gr.Row():
|
| 711 |
+
with gr.Column():
|
| 712 |
+
gr.Markdown("### 📈 详细数据")
|
| 713 |
+
json_output = gr.JSON(label="量子分析结果")
|
| 714 |
+
|
| 715 |
+
with gr.Column():
|
| 716 |
+
gr.Markdown("### 🎨 可视化")
|
| 717 |
+
visual_output = gr.JSON(label="可视化数据")
|
| 718 |
+
|
| 719 |
+
with gr.Row():
|
| 720 |
+
gr.Markdown("""
|
| 721 |
+
### 🚀 系统特性 (修复版)
|
| 722 |
+
- **🎯 作用域边界修复**: 解决control_flow错误包含类作用域问题
|
| 723 |
+
- **🧠 深度计算优化**: 准确的作用域嵌套深度
|
| 724 |
+
- **🔍 变量识别增强**: 改进实例变量识别
|
| 725 |
+
- **⚡ 置信度校准**: 更合理的置信度评分
|
| 726 |
+
- **🛠️ 语义精度提升**: 更精确的语义位置标签
|
| 727 |
+
""")
|
| 728 |
+
|
| 729 |
+
# 事件处理
|
| 730 |
+
analyze_btn.click(
|
| 731 |
+
fn=analyze_code_with_cursor,
|
| 732 |
+
inputs=[code_input, cursor_line, cursor_column],
|
| 733 |
+
outputs=[report_output, json_output, visual_output]
|
| 734 |
+
)
|
| 735 |
+
|
| 736 |
+
# 快速示例按钮
|
| 737 |
+
with gr.Row():
|
| 738 |
+
gr.Markdown("### 🎯 快速测试")
|
| 739 |
+
|
| 740 |
+
vue_example_btn = gr.Button("Vue示例")
|
| 741 |
+
python_example_btn = gr.Button("Python示例")
|
| 742 |
+
js_example_btn = gr.Button("JavaScript示例")
|
| 743 |
+
class_example_btn = gr.Button("类作用域测试")
|
| 744 |
+
|
| 745 |
+
# 示例代码
|
| 746 |
+
vue_example = """<template>
|
| 747 |
+
<div class="dashboard">
|
| 748 |
+
<h1>{{ title }}</h1>
|
| 749 |
+
<button @click="handleClick">点击我</button>
|
| 750 |
+
</div>
|
| 751 |
+
</template>
|
| 752 |
+
|
| 753 |
+
<script setup>
|
| 754 |
+
import { ref } from 'vue'
|
| 755 |
+
|
| 756 |
+
const title = ref('欢迎使用Vision系统')
|
| 757 |
+
const count = ref(0)
|
| 758 |
+
|
| 759 |
+
const handleClick = () => {
|
| 760 |
+
count.value++
|
| 761 |
+
console.log('点击次数:', count.value)
|
| 762 |
+
}
|
| 763 |
+
</script>"""
|
| 764 |
+
|
| 765 |
+
python_example = """def fibonacci(n):
|
| 766 |
+
if n <= 1:
|
| 767 |
+
return n
|
| 768 |
+
else:
|
| 769 |
+
return fibonacci(n-1) + fibonacci(n-2)
|
| 770 |
+
|
| 771 |
+
class MathUtils:
|
| 772 |
+
@staticmethod
|
| 773 |
+
def calculate_sum(numbers):
|
| 774 |
+
total = 0
|
| 775 |
+
for num in numbers:
|
| 776 |
+
total += num
|
| 777 |
+
return total"""
|
| 778 |
+
|
| 779 |
+
class_example = """class TestClass:
|
| 780 |
+
def __init__(self, name):
|
| 781 |
+
self.name = name
|
| 782 |
+
self.data = []
|
| 783 |
+
|
| 784 |
+
def add_item(self, item):
|
| 785 |
+
if item not in self.data:
|
| 786 |
+
self.data.append(item)
|
| 787 |
+
return True
|
| 788 |
+
return False"""
|
| 789 |
+
|
| 790 |
+
def load_example(example_code, line, column):
|
| 791 |
+
return example_code, line, column
|
| 792 |
+
|
| 793 |
+
vue_example_btn.click(
|
| 794 |
+
fn=lambda: load_example(vue_example, 8, 10),
|
| 795 |
+
outputs=[code_input, cursor_line, cursor_column]
|
| 796 |
+
)
|
| 797 |
+
|
| 798 |
+
python_example_btn.click(
|
| 799 |
+
fn=lambda: load_example(python_example, 6, 8),
|
| 800 |
+
outputs=[code_input, cursor_line, cursor_column]
|
| 801 |
+
)
|
| 802 |
+
|
| 803 |
+
js_example_btn.click(
|
| 804 |
+
fn=lambda: load_example(example_code, 4, 8),
|
| 805 |
+
outputs=[code_input, cursor_line, cursor_column]
|
| 806 |
+
)
|
| 807 |
+
|
| 808 |
+
class_example_btn.click(
|
| 809 |
+
fn=lambda: load_example(class_example, 4, 8),
|
| 810 |
+
outputs=[code_input, cursor_line, cursor_column]
|
| 811 |
+
)
|
| 812 |
|
| 813 |
+
# 启动应用
|
| 814 |
if __name__ == "__main__":
|
| 815 |
demo.launch(
|
| 816 |
server_name="0.0.0.0",
|