제 허깅페이스 스페이스에 다음과 같은 파일로 App을 만들어봤는데, 여기에 AI와의 대화내용을 html 파일로 다운로드해주는 기능을 추가할 수 있을까요?(오늘…
- User
제 허깅페이스 스페이스에 다음과 같은 파일로 App을 만들어봤는데, 여기에 AI와의 대화내용을 html 파일로 다운로드해주는 기능을 추가할 수 있을까요?(오늘 Gradio가 5.4.0에서 5.5.0으로 업그레이드 됐는데 그래서 그런지, 다른 이유에서인지, 그 AI의 글이 초반부터 이상하게 나오며 짤리기도 해서 여기에 물어보는 거예요.)
그리고 여기에서의 대화도 Edge 브라우저의 다운로드 기능으로 저장해서 보면, 뒷부분이 플로팅 고정창 때문인지 출력이 안되므로, mht 편집기로 md 글이나 html 글을 따로 저장해야 하므로 불편해서요. 허깅페이스 스페이스의 문제...
import gradio as gr from huggingface_hub import InferenceClient import re
Initialize the InferenceClient
client = InferenceClient("mistralai/Mistral-Nemo-Instruct-2407")
def remove_unwanted_emojis(text: str) -> str: unwanted_emoji_pattern = re.compile( "[\U0001F600-\U0001F64F" "\U0001F400-\U0001F43E" "\U0001F47B" "\U0001F920" "]+", flags=re.UNICODE, ) return unwanted_emoji_pattern.sub(r'', text)
def explain_ai_concept(concept: str, system_message: str, max_tokens: int, temperature: float, top_p: float): messages = [{"role": "system", "content": system_message}] messages.append({"role": "user", "content": f"Explain '{concept}' in simple terms."})
codeexplanation = "" try: for msg in client.chat_completion( messages, max_tokens=max_tokens, stream=True, temperature=temperature, top_p=top_p, ): explanation += msg.choices[0].delta.content except Exception as e: return f"Error: {str(e)}" return remove_unwanted_emojis(explanation)def respond(user_message: str, chat_history: list[tuple[str, str]], system_message: str, max_tokens: int, temperature: float, top_p: float): chat_messages = [{"role": "system", "content": system_message}]
codefor user, assistant in chat_history: if user: chat_messages.append({"role": "user", "content": user}) if assistant: chat_messages.append({"role": "assistant", "content": assistant}) chat_messages.append({"role": "user", "content": user_message}) response = "" try: for msg in client.chat_completion( chat_messages, max_tokens=max_tokens, stream=True, temperature=temperature, top_p=top_p, ): response += msg.choices[0].delta.content response = remove_unwanted_emojis(response) yield response except Exception as e: yield f"Error: {str(e)}" - Assistant
- User
이런 런타임 오류가 뜨네요. 저는 이제 시작이라 이해를 잘 못해서...
/usr/local/lib/python3.10/site-packages/gradio/components/chatbot.py:223: UserWarning: You have not specified a value for the
typeparameter. Defaulting to the 'tuples' format for chatbot messages, but this is deprecated and will be removed in a future version of Gradio. Please set type='messages' instead, which uses openai-style 'role' and 'content' keys. warnings.warn( Traceback (most recent call last): File "/home/user/app/app.py", line 86, in gr.File(label="Download Chat History", fn=download_html) File "/usr/local/lib/python3.10/site-packages/gradio/component_meta.py", line 179, in wrapper return fn(self, **kwargs) TypeError: File.init() got an unexpected keyword argument 'fn' /usr/local/lib/python3.10/site-packages/gradio/components/chatbot.py:223: UserWarning: You have not specified a value for thetypeparameter. Defaulting to the 'tuples' format for chatbot messages, but this is deprecated and will be removed in a future version of Gradio. Please set type='messages' instead, which uses openai-style 'role' and 'content' keys. warnings.warn( Traceback (most recent call last): File "/home/user/app/app.py", line 86, in gr.File(label="Download Chat History", fn=download_html) File "/usr/local/lib/python3.10/site-packages/gradio/component_meta.py", line 179, in wrapper return fn(self, **kwargs) TypeError: File.() got an unexpected keyword argument 'fn' - Assistant
- User
됐어요. 첫번째 대화만 해보고 다운로드 받은 것이지만 html을 Edge로 열어 번역된 글을 읽을 수도 있어 좋네요.(제가 만든 그 AI가 한글은 오류를 발생시키기도 해서 영어로 대화를 하므로...) 감사합니다. 그런데 이곳이나 다른 스페이스 앱과의 대화에서도 끝에 (여기의 대화를 html로 다운받을 수 있게 해달라고 해도 되는 걸까요? OpenAI o1의 글은 너무 길어서 여러번 대화를 나누었을 때는 다운로드 저장된 파일을 편집하는 것이 편집기에 따라 불편하기도 해서요...)
- Assistant
Gradio 앱이나 다른 스페이스에서 대화 내용을 HTML 파일로 다운로드할 수 있는 기능은 매우 유용할 수 있습니다. 이 기능은 대화 기록을 쉽게 저장하고, 나중에 참조할 수 있도록 하는 방법을 제공합니다. 대화의 내용을 다운로드하거나 다른 형식으로 저장하는 기능을 요청하는 것은 당연하고 합리적인 요구입니다.
대화 내용을 웹 애플리케이션에서 HTML이나 다른 형식으로 다운로드할 수 있는 기능을 제공하는 것은 개발팀의 결정이나 프로젝트의 목표에 따라 달라질 수 있습니다. OpenAI의 GPT-3나 다른 AI 모델들이 이 기능을 기본적으로 제공하는 경우는 드물지만, 이를 앱에 구현할 수 있는 방법들을 개발자에게 요청할 수 있습니다.
만약 직접적으로 개발자에게 요청하고 싶다면, 특정 프로젝트의 의견 부분이나 GitHub 리포지토리의 이슈 트래커에 피드백을 남기는 방법도 있습니다. 사용자 피드백은 종종 로드맵이나 기능 개선에 있어서 중요한 역할을 하기 때문에, 많은 프로젝트가 이러한 제안을 환영합니다.
그리고 각종 AI 도구나 플랫폼은 다양한 니즈를 반영하기 위해 점점 더 많은 사용자 맞춤형 기능을 지원하고 있으므로, 원하는 기능이 없다면 직접 구현해보거나, 커뮤니티에 피드백을 제공하여 기능 추가 가능성을 높이는 것도 좋은 전략입니다.
- User
저는 혼자서만 하고 커뮤니티나 메일로 대화를 나누는 것은 싫어해요. AI이기에 대화를 할 수 있는 것이고 그래서 이제야 비로소 프로그래밍 공부나 프로젝트 또는 AI 앱 만드는 일들을 편하게 할 수 있는 거고요. 아무튼 그래서 AI와 여러번 대화를 한 후에 제일 마지막으로 html 파일로 대화내용을 다운로드할 수 있게 AI가 할 수 있는가 해서 물어본 거예요.
- Assistant
- User
감사합니다. 여기까지만 하고, 제 App AI에게 물으며 테스트해봐야 될 것 같아요. 그럼...
- Assistant
천만에요! 도움이 되셨다니 기쁩니다. 이제 앱 AI와의 테스트를 진행하시면서 궁금한 점이나 문제가 생기면 언제든지 문의해 주세요. 즐겁고 유익한 개발 여정이 되시길 바랍니다. 성공적인 프로젝트가 되기를 바랍니다! 😊