Download app.py from ngoccs/itnbkcs: direct link, hf CLI and curl.
- Browser
- Download file 613 Bytes
-
https://huggingface.co/spaces/ngoccs/itnbkcs/resolve/main/app.py
- Command line
-
hf download hf://spaces/ngoccs/itnbkcs/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ngoccs/itnbkcs/resolve/main/app.py
613 Bytes
| import gradio as gr | |
| import os | |
| from google import genai | |
| # Lấy API key từ HuggingFace Secrets | |
| client = genai.Client(api_key=os.getenv("GOOGLE_API_KEY")) | |
| def chat_with_ai(message): | |
| if not message.strip(): | |
| return "⚠️ Bạn chưa nhập nội dung." | |
| response = client.models.generate_content( | |
| model="gemini-1.5-flash", | |
| contents=message | |
| ) | |
| return response.text | |
| interface = gr.Interface( | |
| fn=chat_with_ai, | |
| inputs="text", | |
| outputs="text", | |
| title="Trợ lý học lập trình", | |
| description="AI hỗ trợ học sinh luyện tập" | |
| ) | |
| interface.launch() |