Spaces:
Running
Running
Update app-backup10.py
Browse files- app-backup10.py +190 -95
app-backup10.py
CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
|
|
2 |
from huggingface_hub import InferenceClient, HfApi
|
3 |
import os
|
4 |
import requests
|
5 |
-
from typing import List, Dict, Union
|
6 |
import traceback
|
7 |
from PIL import Image
|
8 |
from io import BytesIO
|
@@ -11,6 +11,7 @@ from gradio_client import Client
|
|
11 |
import time
|
12 |
import threading
|
13 |
import json
|
|
|
14 |
|
15 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
16 |
hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus-08-2024", token=HF_TOKEN)
|
@@ -61,13 +62,16 @@ def get_space_structure(space_id: str) -> Dict:
|
|
61 |
return {"error": f"API request error: {str(e)}"}
|
62 |
|
63 |
def format_tree_structure(tree_data: Dict, indent: str = "") -> str:
|
64 |
-
|
65 |
-
|
66 |
-
|
|
|
|
|
|
|
67 |
formatted += format_tree_structure(child, indent + " ")
|
68 |
return formatted
|
69 |
|
70 |
-
def summarize_code(app_content: str)
|
71 |
system_message = "๋น์ ์ Python ์ฝ๋๋ฅผ ๋ถ์ํ๊ณ ์์ฝํ๋ AI ์กฐ์์
๋๋ค. ์ฃผ์ด์ง ์ฝ๋๋ฅผ 3์ค ์ด๋ด๋ก ๊ฐ๊ฒฐํ๊ฒ ์์ฝํด์ฃผ์ธ์."
|
72 |
user_message = f"๋ค์ Python ์ฝ๋๋ฅผ 3์ค ์ด๋ด๋ก ์์ฝํด์ฃผ์ธ์:\n\n{app_content}"
|
73 |
|
@@ -82,7 +86,7 @@ def summarize_code(app_content: str) -> str:
|
|
82 |
except Exception as e:
|
83 |
return f"์์ฝ ์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
84 |
|
85 |
-
def analyze_code(app_content: str)
|
86 |
system_message = """๋น์ ์ Python ์ฝ๋๋ฅผ ๋ถ์ํ๋ AI ์กฐ์์
๋๋ค. ์ฃผ์ด์ง ์ฝ๋๋ฅผ ๋ถ์ํ์ฌ ๋ค์ ํญ๋ชฉ์ ๋ํด ์ค๋ช
ํด์ฃผ์ธ์:
|
87 |
A. ๋ฐฐ๊ฒฝ ๋ฐ ํ์์ฑ
|
88 |
B. ๊ธฐ๋ฅ์ ํจ์ฉ์ฑ ๋ฐ ๊ฐ์น
|
@@ -103,7 +107,7 @@ def analyze_code(app_content: str) -> str:
|
|
103 |
except Exception as e:
|
104 |
return f"๋ถ์ ์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
105 |
|
106 |
-
def explain_usage(app_content: str)
|
107 |
system_message = "๋น์ ์ Python ์ฝ๋๋ฅผ ๋ถ์ํ์ฌ ์ฌ์ฉ๋ฒ์ ์ค๋ช
ํ๋ AI ์กฐ์์
๋๋ค. ์ฃผ์ด์ง ์ฝ๋๋ฅผ ๋ฐํ์ผ๋ก ๋ง์น ํ๋ฉด์ ๋ณด๋ ๊ฒ์ฒ๋ผ ์ฌ์ฉ๋ฒ์ ์์ธํ ์ค๋ช
ํด์ฃผ์ธ์. Markdown ํ์์ผ๋ก ์ถ๋ ฅํ์ธ์."
|
108 |
user_message = f"๋ค์ Python ์ฝ๋์ ์ฌ์ฉ๋ฒ์ ์ค๋ช
ํด์ฃผ์ธ์:\n\n{app_content}"
|
109 |
|
@@ -118,33 +122,73 @@ def explain_usage(app_content: str) -> str:
|
|
118 |
except Exception as e:
|
119 |
return f"์ฌ์ฉ๋ฒ ์ค๋ช
์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
def analyze_space(url: str, progress=gr.Progress()):
|
122 |
try:
|
123 |
space_id = url.split('spaces/')[-1]
|
124 |
|
|
|
|
|
|
|
|
|
125 |
progress(0.1, desc="ํ์ผ ๊ตฌ์กฐ ๋ถ์ ์ค...")
|
126 |
tree_structure = get_space_structure(space_id)
|
|
|
|
|
127 |
tree_view = format_tree_structure(tree_structure)
|
128 |
|
129 |
progress(0.3, desc="app.py ๋ด์ฉ ๊ฐ์ ธ์ค๋ ์ค...")
|
130 |
app_content = get_file_content(space_id, "app.py")
|
131 |
|
132 |
-
progress(0.
|
133 |
summary = summarize_code(app_content)
|
134 |
|
135 |
-
progress(0.
|
136 |
analysis = analyze_code(app_content)
|
137 |
|
138 |
-
progress(0.
|
139 |
usage = explain_usage(app_content)
|
140 |
|
|
|
|
|
|
|
141 |
progress(1.0, desc="์๋ฃ")
|
142 |
-
return
|
143 |
except Exception as e:
|
144 |
print(f"Error in analyze_space: {str(e)}")
|
145 |
print(traceback.format_exc())
|
146 |
-
return f"์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}", "", "", "", "",
|
147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
def create_ui():
|
150 |
try:
|
@@ -160,107 +204,142 @@ def create_ui():
|
|
160 |
overflow-y: auto !important;
|
161 |
max-height: calc((100vh - 200px) / 5) !important;
|
162 |
}
|
|
|
|
|
|
|
|
|
163 |
.full-height {
|
164 |
-
height: calc(
|
165 |
overflow-y: auto !important;
|
166 |
}
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
}
|
179 |
"""
|
180 |
|
181 |
-
with gr.Blocks(
|
182 |
-
gr.Markdown("# HuggingFace
|
183 |
|
184 |
-
with gr.
|
185 |
-
with gr.
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
|
198 |
-
|
199 |
-
|
|
|
|
|
200 |
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
with gr.Column(scale=4): # ์ค๋ฅธ์ชฝ 40%
|
210 |
-
with gr.Group(elem_classes="output-group full-height"):
|
211 |
-
code_tabs = gr.Tabs()
|
212 |
-
with code_tabs:
|
213 |
-
app_py_tab = gr.TabItem("app.py")
|
214 |
-
with app_py_tab:
|
215 |
-
app_py_content = gr.Code(language="python", label="app.py", lines=30)
|
216 |
|
217 |
-
|
218 |
-
tree_structure_state = gr.State()
|
219 |
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
files = []
|
226 |
-
if node["type"] == "file":
|
227 |
-
files.append(node)
|
228 |
-
elif node["type"] == "directory":
|
229 |
-
for child in node.get("children", []):
|
230 |
-
files.extend(get_files(child))
|
231 |
-
return files
|
232 |
|
233 |
-
|
234 |
-
return [[file["path"], f'<button onclick="openFile(\'{file["path"]}\', \'{space_id}\')">์ด๊ธฐ</button>'] for file in files]
|
235 |
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
|
240 |
analyze_button.click(
|
241 |
analyze_space,
|
242 |
inputs=[url_input],
|
243 |
-
outputs=[
|
244 |
).then(
|
245 |
-
|
246 |
-
inputs=[
|
247 |
-
outputs=[
|
248 |
-
)
|
249 |
-
|
250 |
-
file_path_input = gr.Textbox(visible=False)
|
251 |
-
space_id_input = gr.Textbox(visible=False)
|
252 |
-
|
253 |
-
def handle_file_open(file_path, space_id):
|
254 |
-
return file_path, space_id
|
255 |
-
|
256 |
-
file_path_input.change(
|
257 |
-
open_file,
|
258 |
-
inputs=[file_path_input, space_id_input],
|
259 |
-
outputs=[code_tabs, code_tabs]
|
260 |
)
|
261 |
|
262 |
-
#
|
263 |
-
gr.
|
264 |
|
265 |
return demo
|
266 |
|
@@ -271,9 +350,25 @@ def create_ui():
|
|
271 |
|
272 |
if __name__ == "__main__":
|
273 |
try:
|
|
|
274 |
demo = create_ui()
|
|
|
|
|
|
|
275 |
demo.queue()
|
276 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
277 |
except Exception as e:
|
278 |
print(f"Error in main: {str(e)}")
|
279 |
-
print(
|
|
|
|
|
|
2 |
from huggingface_hub import InferenceClient, HfApi
|
3 |
import os
|
4 |
import requests
|
5 |
+
from typing import List, Dict, Union, Tuple
|
6 |
import traceback
|
7 |
from PIL import Image
|
8 |
from io import BytesIO
|
|
|
11 |
import time
|
12 |
import threading
|
13 |
import json
|
14 |
+
import re
|
15 |
|
16 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
17 |
hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus-08-2024", token=HF_TOKEN)
|
|
|
62 |
return {"error": f"API request error: {str(e)}"}
|
63 |
|
64 |
def format_tree_structure(tree_data: Dict, indent: str = "") -> str:
|
65 |
+
if "error" in tree_data:
|
66 |
+
return tree_data["error"]
|
67 |
+
|
68 |
+
formatted = f"{indent}{'๐' if tree_data.get('type') == 'directory' else '๐'} {tree_data.get('name', 'Unknown')}\n"
|
69 |
+
if tree_data.get("type") == "directory":
|
70 |
+
for child in sorted(tree_data.get("children", []), key=lambda x: (x.get("type", "") != "directory", x.get("name", ""))):
|
71 |
formatted += format_tree_structure(child, indent + " ")
|
72 |
return formatted
|
73 |
|
74 |
+
def summarize_code(app_content: str):
|
75 |
system_message = "๋น์ ์ Python ์ฝ๋๋ฅผ ๋ถ์ํ๊ณ ์์ฝํ๋ AI ์กฐ์์
๋๋ค. ์ฃผ์ด์ง ์ฝ๋๋ฅผ 3์ค ์ด๋ด๋ก ๊ฐ๊ฒฐํ๊ฒ ์์ฝํด์ฃผ์ธ์."
|
76 |
user_message = f"๋ค์ Python ์ฝ๋๋ฅผ 3์ค ์ด๋ด๋ก ์์ฝํด์ฃผ์ธ์:\n\n{app_content}"
|
77 |
|
|
|
86 |
except Exception as e:
|
87 |
return f"์์ฝ ์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
88 |
|
89 |
+
def analyze_code(app_content: str):
|
90 |
system_message = """๋น์ ์ Python ์ฝ๋๋ฅผ ๋ถ์ํ๋ AI ์กฐ์์
๋๋ค. ์ฃผ์ด์ง ์ฝ๋๋ฅผ ๋ถ์ํ์ฌ ๋ค์ ํญ๋ชฉ์ ๋ํด ์ค๋ช
ํด์ฃผ์ธ์:
|
91 |
A. ๋ฐฐ๊ฒฝ ๋ฐ ํ์์ฑ
|
92 |
B. ๊ธฐ๋ฅ์ ํจ์ฉ์ฑ ๋ฐ ๊ฐ์น
|
|
|
107 |
except Exception as e:
|
108 |
return f"๋ถ์ ์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
109 |
|
110 |
+
def explain_usage(app_content: str):
|
111 |
system_message = "๋น์ ์ Python ์ฝ๋๋ฅผ ๋ถ์ํ์ฌ ์ฌ์ฉ๋ฒ์ ์ค๋ช
ํ๋ AI ์กฐ์์
๋๋ค. ์ฃผ์ด์ง ์ฝ๋๋ฅผ ๋ฐํ์ผ๋ก ๋ง์น ํ๋ฉด์ ๋ณด๋ ๊ฒ์ฒ๋ผ ์ฌ์ฉ๋ฒ์ ์์ธํ ์ค๋ช
ํด์ฃผ์ธ์. Markdown ํ์์ผ๋ก ์ถ๋ ฅํ์ธ์."
|
112 |
user_message = f"๋ค์ Python ์ฝ๋์ ์ฌ์ฉ๋ฒ์ ์ค๋ช
ํด์ฃผ์ธ์:\n\n{app_content}"
|
113 |
|
|
|
122 |
except Exception as e:
|
123 |
return f"์ฌ์ฉ๋ฒ ์ค๋ช
์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
124 |
|
125 |
+
def adjust_lines_for_code(code_content: str, min_lines: int = 10, max_lines: int = 100) -> int:
|
126 |
+
"""
|
127 |
+
์ฝ๋ ๋ด์ฉ์ ๋ฐ๋ผ lines ์๋ฅผ ๋์ ์ผ๋ก ์กฐ์ ํฉ๋๋ค.
|
128 |
+
|
129 |
+
Parameters:
|
130 |
+
- code_content (str): ์ฝ๋ ํ
์คํธ ๋ด์ฉ
|
131 |
+
- min_lines (int): ์ต์ lines ์
|
132 |
+
- max_lines (int): ์ต๋ lines ์
|
133 |
+
|
134 |
+
Returns:
|
135 |
+
- int: ์ค์ ๋ lines ์
|
136 |
+
"""
|
137 |
+
# ์ฝ๋์ ์ค ์ ๊ณ์ฐ
|
138 |
+
num_lines = len(code_content.split('\n'))
|
139 |
+
# ์ค ์๊ฐ min_lines๋ณด๋ค ์ ๋ค๋ฉด min_lines ์ฌ์ฉ, max_lines๋ณด๋ค ํฌ๋ฉด max_lines ์ฌ์ฉ
|
140 |
+
return min(max(num_lines, min_lines), max_lines)
|
141 |
+
|
142 |
def analyze_space(url: str, progress=gr.Progress()):
|
143 |
try:
|
144 |
space_id = url.split('spaces/')[-1]
|
145 |
|
146 |
+
# Space ID ์ ํจ์ฑ ๊ฒ์ฌ ์์
|
147 |
+
if not re.match(r'^[\w.-]+/[\w.-]+$', space_id):
|
148 |
+
raise ValueError(f"Invalid Space ID format: {space_id}")
|
149 |
+
|
150 |
progress(0.1, desc="ํ์ผ ๊ตฌ์กฐ ๋ถ์ ์ค...")
|
151 |
tree_structure = get_space_structure(space_id)
|
152 |
+
if "error" in tree_structure:
|
153 |
+
raise ValueError(tree_structure["error"])
|
154 |
tree_view = format_tree_structure(tree_structure)
|
155 |
|
156 |
progress(0.3, desc="app.py ๋ด์ฉ ๊ฐ์ ธ์ค๋ ์ค...")
|
157 |
app_content = get_file_content(space_id, "app.py")
|
158 |
|
159 |
+
progress(0.5, desc="์ฝ๋ ์์ฝ ์ค...")
|
160 |
summary = summarize_code(app_content)
|
161 |
|
162 |
+
progress(0.7, desc="์ฝ๋ ๋ถ์ ์ค...")
|
163 |
analysis = analyze_code(app_content)
|
164 |
|
165 |
+
progress(0.9, desc="์ฌ์ฉ๋ฒ ์ค๋ช
์์ฑ ์ค...")
|
166 |
usage = explain_usage(app_content)
|
167 |
|
168 |
+
# ์ค ์ ๊ณ์ฐํ์ฌ lines ์ค์
|
169 |
+
app_py_lines = adjust_lines_for_code(app_content)
|
170 |
+
|
171 |
progress(1.0, desc="์๋ฃ")
|
172 |
+
return app_content, tree_view, tree_structure, space_id, summary, analysis, usage, app_py_lines
|
173 |
except Exception as e:
|
174 |
print(f"Error in analyze_space: {str(e)}")
|
175 |
print(traceback.format_exc())
|
176 |
+
return f"์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}", "", None, "", "", "", "", 10
|
177 |
|
178 |
+
def respond(message: str, chat_history: List[Dict[str, str]], max_tokens: int, temperature: float, top_p: float) -> str:
|
179 |
+
system_message = """๋น์ ์ ํ๊น
ํ์ด์ค์ ํนํ๋ AI ์ฝ๋ฉ ์ ๋ฌธ๊ฐ์
๋๋ค. ์ฌ์ฉ์์ ์ง๋ฌธ์ ์น์ ํ๊ณ ์์ธํ๊ฒ ๋ต๋ณํด์ฃผ์ธ์.
|
180 |
+
Gradio ํน์ฑ์ ์ ํํ ์ธ์ํ๊ณ Requirements.txt ๋๋ฝ์์ด ์ฝ๋ฉ๊ณผ ์ค๋ฅ๋ฅผ ํด๊ฒฐํด์ผ ํฉ๋๋ค.
|
181 |
+
ํญ์ ์ ํํ๊ณ ์ ์ฉํ ์ ๋ณด๋ฅผ ์ ๊ณตํ๋๋ก ๋
ธ๋ ฅํ์ธ์."""
|
182 |
+
|
183 |
+
messages = [{"role": "system", "content": system_message}]
|
184 |
+
messages.extend(chat_history)
|
185 |
+
messages.append({"role": "user", "content": message})
|
186 |
+
|
187 |
+
try:
|
188 |
+
response = hf_client.chat_completion(messages, max_tokens=max_tokens, temperature=temperature, top_p=top_p)
|
189 |
+
return response.choices[0].message.content
|
190 |
+
except Exception as e:
|
191 |
+
return f"์๋ต ์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
192 |
|
193 |
def create_ui():
|
194 |
try:
|
|
|
204 |
overflow-y: auto !important;
|
205 |
max-height: calc((100vh - 200px) / 5) !important;
|
206 |
}
|
207 |
+
.tree-view-scroll {
|
208 |
+
overflow-y: auto !important;
|
209 |
+
max-height: calc((100vh - 200px) / 2) !important;
|
210 |
+
}
|
211 |
.full-height {
|
212 |
+
height: calc(200em * 1.2) !important;
|
213 |
overflow-y: auto !important;
|
214 |
}
|
215 |
+
.code-box {
|
216 |
+
overflow-x: auto !important;
|
217 |
+
overflow-y: auto !important;
|
218 |
+
white-space: pre !important;
|
219 |
+
word-wrap: normal !important;
|
220 |
+
height: 100% !important;
|
221 |
+
}
|
222 |
+
.code-box > div {
|
223 |
+
min-width: 100% !important;
|
224 |
+
}
|
225 |
+
.code-box > div > textarea {
|
226 |
+
word-break: normal !important;
|
227 |
+
overflow-wrap: normal !important;
|
228 |
+
}
|
229 |
+
.tab-nav {
|
230 |
+
background-color: #2c3e50;
|
231 |
+
border-radius: 5px 5px 0 0;
|
232 |
+
overflow: hidden;
|
233 |
+
}
|
234 |
+
.tab-nav button {
|
235 |
+
color: #ecf0f1 !important;
|
236 |
+
background-color: #34495e;
|
237 |
+
border: none;
|
238 |
+
padding: 10px 20px;
|
239 |
+
margin: 0;
|
240 |
+
transition: background-color 0.3s;
|
241 |
+
font-size: 16px;
|
242 |
+
font-weight: bold;
|
243 |
+
}
|
244 |
+
.tab-nav button:hover {
|
245 |
+
background-color: #2980b9;
|
246 |
+
}
|
247 |
+
.tab-nav button.selected {
|
248 |
+
color: #2c3e50 !important;
|
249 |
+
background-color: #ecf0f1;
|
250 |
+
}
|
251 |
+
input[type="text"], textarea {
|
252 |
+
color: #2c3e50 !important;
|
253 |
+
background-color: #ecf0f1 !important;
|
254 |
}
|
255 |
"""
|
256 |
|
257 |
+
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
258 |
+
gr.Markdown("# Mouse: HuggingFace")
|
259 |
|
260 |
+
with gr.Tabs() as tabs:
|
261 |
+
with gr.TabItem("๋ถ์"):
|
262 |
+
with gr.Row():
|
263 |
+
with gr.Column(scale=6): # ์ผ์ชฝ 60%
|
264 |
+
url_input = gr.Textbox(label="HuggingFace Space URL")
|
265 |
+
analyze_button = gr.Button("๋ถ์")
|
266 |
+
|
267 |
+
with gr.Group(elem_classes="output-group scroll-lock"):
|
268 |
+
summary_output = gr.Markdown(label="์์ฝ (3์ค ์ด๋ด)")
|
269 |
+
|
270 |
+
with gr.Group(elem_classes="output-group scroll-lock"):
|
271 |
+
analysis_output = gr.Markdown(label="๋ถ์")
|
272 |
+
|
273 |
+
with gr.Group(elem_classes="output-group scroll-lock"):
|
274 |
+
usage_output = gr.Markdown(label="์ฌ์ฉ๋ฒ")
|
275 |
+
|
276 |
+
with gr.Group(elem_classes="output-group tree-view-scroll"): # ํธ๋ฆฌ ๋ทฐ ์คํฌ๋กค ์ถ๊ฐ
|
277 |
+
tree_view_output = gr.Textbox(label="ํ์ผ ๊ตฌ์กฐ (Tree View)", lines=30)
|
278 |
+
|
279 |
+
with gr.Column(scale=4): # ์ค๋ฅธ์ชฝ 40%
|
280 |
+
with gr.Group(elem_classes="output-group full-height"):
|
281 |
+
code_tabs = gr.Tabs()
|
282 |
+
with code_tabs:
|
283 |
+
app_py_tab = gr.TabItem("app.py")
|
284 |
+
with app_py_tab:
|
285 |
+
app_py_content = gr.Code(
|
286 |
+
language="python",
|
287 |
+
label="app.py",
|
288 |
+
lines=200,
|
289 |
+
elem_classes="full-height code-box"
|
290 |
+
)
|
291 |
+
requirements_tab = gr.TabItem("requirements.txt")
|
292 |
+
with requirements_tab:
|
293 |
+
requirements_content = gr.Textbox(
|
294 |
+
label="requirements.txt",
|
295 |
+
lines=200,
|
296 |
+
elem_classes="full-height code-box"
|
297 |
+
)
|
298 |
+
|
299 |
+
with gr.TabItem("AI ์ฝ๋ฉ"):
|
300 |
+
chatbot = gr.Chatbot(label="๋ํ", type='messages')
|
301 |
+
msg = gr.Textbox(label="๋ฉ์์ง")
|
302 |
|
303 |
+
# ์จ๊ฒจ์ง ์ํ๋ก ํ๋ผ๋ฏธํฐ ์ค์
|
304 |
+
max_tokens = gr.Slider(minimum=1, maximum=8000, value=4000, label="Max Tokens", visible=False)
|
305 |
+
temperature = gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature", visible=False)
|
306 |
+
top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P", visible=False)
|
307 |
|
308 |
+
examples = [
|
309 |
+
["์์ธํ ์ฌ์ฉ ๋ฐฉ๋ฒ์ ๋ง์น ํ๋ฉด์ ๋ณด๋ฉด์ ์ค๋ช
ํ๋ฏ์ด 4000 ํ ํฐ ์ด์ ์์ธํ ์ค๋ช
ํ๋ผ"],
|
310 |
+
["FAQ 20๊ฑด์ ์์ธํ๊ฒ ์์ฑํ๋ผ. 4000ํ ํฐ ์ด์ ์ฌ์ฉํ๋ผ."],
|
311 |
+
["์ฌ์ฉ ๋ฐฉ๋ฒ๊ณผ ์ฐจ๋ณ์ , ํน์ง, ๊ฐ์ ์ ์ค์ฌ์ผ๋ก 4000 ํ ํฐ ์ด์ ์ ํ๋ธ ์์ ์คํฌ๋ฆฝํธ ํํ๋ก ์์ฑํ๋ผ"],
|
312 |
+
["๋ณธ ์๋น์ค๋ฅผ SEO ์ต์ ํํ์ฌ ๋ธ๋ก๊ทธ ํฌ์คํธ(๋ฐฐ๊ฒฝ ๋ฐ ํ์์ฑ, ๊ธฐ์กด ์ ์ฌ ์๋น์ค์ ๋น๊ตํ์ฌ ํน์ฅ์ , ํ์ฉ์ฒ, ๊ฐ์น, ๊ธฐ๋ํจ๊ณผ, ๊ฒฐ๋ก ์ ํฌํจ)๋ก 4000 ํ ํฐ ์ด์ ์์ฑํ๋ผ"],
|
313 |
+
["ํนํ ์ถ์์ ํ์ฉํ ๊ธฐ์ ๋ฐ ๋น์ฆ๋์ค๋ชจ๋ธ ์ธก๋ฉด์ ํฌํจํ์ฌ ํนํ ์ถ์์ ๊ตฌ์ฑ์ ๋ง๊ฒ ํ์ ์ ์ธ ์ฐฝ์ ๋ฐ๋ช
๋ด์ฉ์ ์ค์ฌ์ผ๋ก 4000ํ ํฐ ์ด์ ์์ฑํ๋ผ."],
|
314 |
+
["๊ณ์ ์ด์ด์ ๋ต๋ณํ๋ผ"],
|
315 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
316 |
|
317 |
+
gr.Examples(examples, inputs=msg)
|
|
|
318 |
|
319 |
+
def respond_wrapper(message, chat_history, max_tokens, temperature, top_p):
|
320 |
+
bot_message = respond(message, chat_history, max_tokens, temperature, top_p)
|
321 |
+
chat_history.append({"role": "user", "content": message})
|
322 |
+
chat_history.append({"role": "assistant", "content": bot_message})
|
323 |
+
return "", chat_history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
324 |
|
325 |
+
msg.submit(respond_wrapper, [msg, chatbot, max_tokens, temperature, top_p], [msg, chatbot])
|
|
|
326 |
|
327 |
+
space_id_state = gr.State()
|
328 |
+
tree_structure_state = gr.State()
|
329 |
+
app_py_content_lines = gr.State()
|
330 |
|
331 |
analyze_button.click(
|
332 |
analyze_space,
|
333 |
inputs=[url_input],
|
334 |
+
outputs=[app_py_content, tree_view_output, tree_structure_state, space_id_state, summary_output, analysis_output, usage_output, app_py_content_lines]
|
335 |
).then(
|
336 |
+
lambda space_id: get_file_content(space_id, "requirements.txt"),
|
337 |
+
inputs=[space_id_state],
|
338 |
+
outputs=[requirements_content]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
339 |
)
|
340 |
|
341 |
+
# lines ์๋ฅผ ๋์ ์ผ๋ก ์ค์
|
342 |
+
app_py_content.change(lambda lines: gr.update(lines=lines), inputs=[app_py_content_lines], outputs=[app_py_content])
|
343 |
|
344 |
return demo
|
345 |
|
|
|
350 |
|
351 |
if __name__ == "__main__":
|
352 |
try:
|
353 |
+
print("Starting HuggingFace Space Analyzer...")
|
354 |
demo = create_ui()
|
355 |
+
print("UI created successfully.")
|
356 |
+
|
357 |
+
print("Configuring Gradio queue...")
|
358 |
demo.queue()
|
359 |
+
print("Gradio queue configured.")
|
360 |
+
|
361 |
+
print("Launching Gradio app...")
|
362 |
+
demo.launch(
|
363 |
+
server_name="0.0.0.0",
|
364 |
+
server_port=7860,
|
365 |
+
share=False,
|
366 |
+
debug=True,
|
367 |
+
show_api=False
|
368 |
+
)
|
369 |
+
print("Gradio app launched successfully.")
|
370 |
except Exception as e:
|
371 |
print(f"Error in main: {str(e)}")
|
372 |
+
print("Detailed error information:")
|
373 |
+
print(traceback.format_exc())
|
374 |
+
raise
|