Spaces:
Running
Running
update oauth
Browse files
README.md
CHANGED
|
@@ -8,6 +8,7 @@ sdk_version: 5.23.3
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
disable_embedding: true
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
@@ -24,6 +25,7 @@ An ultra-clean AI-powered code generation application using Hugging Face inferen
|
|
| 24 |
- **Live Preview**: Renders generated HTML code in real-time
|
| 25 |
- **History Management**: Keeps track of conversation history
|
| 26 |
- **Streaming**: Real-time code generation with streaming responses
|
|
|
|
| 27 |
|
| 28 |
## Project Structure
|
| 29 |
|
|
@@ -54,11 +56,12 @@ anycoder/
|
|
| 54 |
|
| 55 |
## Usage
|
| 56 |
|
| 57 |
-
1.
|
| 58 |
-
2.
|
| 59 |
-
3.
|
| 60 |
-
4.
|
| 61 |
-
5.
|
|
|
|
| 62 |
|
| 63 |
## Code Example
|
| 64 |
|
|
@@ -89,4 +92,5 @@ The application uses:
|
|
| 89 |
- **Gradio**: For the web interface
|
| 90 |
- **Hugging Face Hub**: For model inference
|
| 91 |
- **ModelScope Studio**: For UI components
|
|
|
|
| 92 |
- **Streaming**: For real-time code generation
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
disable_embedding: true
|
| 11 |
+
hf_oauth: true
|
| 12 |
---
|
| 13 |
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 25 |
- **Live Preview**: Renders generated HTML code in real-time
|
| 26 |
- **History Management**: Keeps track of conversation history
|
| 27 |
- **Streaming**: Real-time code generation with streaming responses
|
| 28 |
+
- **OAuth Login Required**: Users must sign in with their Hugging Face account to use code generation features
|
| 29 |
|
| 30 |
## Project Structure
|
| 31 |
|
|
|
|
| 56 |
|
| 57 |
## Usage
|
| 58 |
|
| 59 |
+
1. **Sign in with your Hugging Face account** using the login button at the top left.
|
| 60 |
+
2. Enter your application requirements in the text area
|
| 61 |
+
3. Click "send" to generate code
|
| 62 |
+
4. View the generated code in the code drawer
|
| 63 |
+
5. See the live preview in the sandbox area
|
| 64 |
+
6. Use example cards for quick prompts
|
| 65 |
|
| 66 |
## Code Example
|
| 67 |
|
|
|
|
| 92 |
- **Gradio**: For the web interface
|
| 93 |
- **Hugging Face Hub**: For model inference
|
| 94 |
- **ModelScope Studio**: For UI components
|
| 95 |
+
- **OAuth Login**: Requires users to sign in with Hugging Face for code generation
|
| 96 |
- **Streaming**: For real-time code generation
|
app.py
CHANGED
|
@@ -249,56 +249,66 @@ with gr.Blocks(css_paths="app.css") as demo:
|
|
| 249 |
with antd.Tabs.Item(key="loading"):
|
| 250 |
loading = antd.Spin(True, tip="coding...", size="large", elem_classes="right_content")
|
| 251 |
|
| 252 |
-
def generation_code(query: Optional[str], _setting: Dict[str, str], _history: Optional[History]):
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
|
| 299 |
-
btn.click(
|
| 300 |
-
|
| 301 |
-
|
|
|
|
|
|
|
| 302 |
|
| 303 |
clear_btn.click(clear_history, inputs=[], outputs=[history])
|
| 304 |
|
|
|
|
| 249 |
with antd.Tabs.Item(key="loading"):
|
| 250 |
loading = antd.Spin(True, tip="coding...", size="large", elem_classes="right_content")
|
| 251 |
|
| 252 |
+
def generation_code(query: Optional[str], _setting: Dict[str, str], _history: Optional[History], profile: gr.OAuthProfile | None):
|
| 253 |
+
if profile is None:
|
| 254 |
+
return (
|
| 255 |
+
"Please sign in with Hugging Face to use this feature.",
|
| 256 |
+
_history,
|
| 257 |
+
None,
|
| 258 |
+
gr.update(active_key="empty"),
|
| 259 |
+
gr.update(open=True),
|
| 260 |
+
)
|
| 261 |
+
if query is None:
|
| 262 |
+
query = ''
|
| 263 |
+
if _history is None:
|
| 264 |
+
_history = []
|
| 265 |
+
messages = history_to_messages(_history, _setting['system'])
|
| 266 |
+
messages.append({'role': 'user', 'content': query})
|
| 267 |
|
| 268 |
+
try:
|
| 269 |
+
completion = client.chat.completions.create(
|
| 270 |
+
model="deepseek-ai/DeepSeek-V3-0324",
|
| 271 |
+
messages=messages,
|
| 272 |
+
stream=True
|
| 273 |
+
)
|
| 274 |
+
|
| 275 |
+
content = ""
|
| 276 |
+
for chunk in completion:
|
| 277 |
+
if chunk.choices[0].delta.content:
|
| 278 |
+
content += chunk.choices[0].delta.content
|
| 279 |
+
yield {
|
| 280 |
+
code_output: content,
|
| 281 |
+
state_tab: gr.update(active_key="loading"),
|
| 282 |
+
code_drawer: gr.update(open=True),
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
# Final response
|
| 286 |
+
_history = messages_to_history(messages + [{
|
| 287 |
+
'role': 'assistant',
|
| 288 |
+
'content': content
|
| 289 |
+
}])
|
| 290 |
+
|
| 291 |
+
yield {
|
| 292 |
+
code_output: content,
|
| 293 |
+
history: _history,
|
| 294 |
+
sandbox: send_to_sandbox(remove_code_block(content)),
|
| 295 |
+
state_tab: gr.update(active_key="render"),
|
| 296 |
+
code_drawer: gr.update(open=False),
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
except Exception as e:
|
| 300 |
+
error_message = f"Error: {str(e)}"
|
| 301 |
+
yield {
|
| 302 |
+
code_output: error_message,
|
| 303 |
+
state_tab: gr.update(active_key="empty"),
|
| 304 |
+
code_drawer: gr.update(open=True),
|
| 305 |
+
}
|
| 306 |
|
| 307 |
+
btn.click(
|
| 308 |
+
generation_code,
|
| 309 |
+
inputs=[input, setting, history, gr.OAuthProfile()],
|
| 310 |
+
outputs=[code_output, history, sandbox, state_tab, code_drawer]
|
| 311 |
+
)
|
| 312 |
|
| 313 |
clear_btn.click(clear_history, inputs=[], outputs=[history])
|
| 314 |
|