Spaces:
Runtime error
Runtime error
Update app.py
Browse files123459 unmodified lines1516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667import gradio as grimport os# Install the groq package if it is not installedtry:9 unmodified linesclient = Groq(api_key=groq_key)class SimpleChatBot:def __init__(self):self.initial_prompt = [{"role": "system","content": "你是一個老師"}]def get_response(self, message, chat_history):messages = self.initial_prompt + chat_historymessages.append({"role": "user", "content": message})completion = client.chat.completions.create(model="llama3-8b-8192",messages=messages,temperature=1,max_tokens=1024,top_p=1,stream=True,stop=None,)response_content = ""for chunk in completion:response_content += chunk.choices[0].delta.content or ""return response_contentchatbot = SimpleChatBot()def respond(message, chat_history):chat_history = [{"role": entry["role"], "content": entry["content"]} for entry in chat_history]response = chatbot.get_response(message, chat_history)chat_history.append({"role": "user", "content": message})chat_history.append({"role": "assistant", "content": response})return chat_history, ""with gr.Blocks(title="簡單的Gradio聊天機器人") as demo:gr.Markdown("# 簡單的Gradio聊天機器人")chatbot_interface = gr.Chatbot(type="messages")with gr.Row():user_input = gr.Textbox(placeholder="輸入訊息...", label="你的訊息")send_button = gr.Button("發送")send_button.click(respond, inputs=[user_input, chatbot_interface], outputs=[chatbot_interface, user_input])demo.launch(share=True)1234569 unmodified lines16171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061import gradio as grimport osfrom groq import Groq# Install the groq package if it is not installedtry:9 unmodified linesclient = Groq(api_key=groq_key)class SpellChecker:def __init__(self):passdef check_spelling(self, text):completion = client.chat.completions.create(model="llama3-8b-8192",messages=[{"role": "system","content": "你是一個老師,請幫我挑錯字。"},{"role": "user","content": text}],temperature=1,max_tokens=1024,top_p=1,stream=False,stop=None,)response_content = completion.choices[0].message["content"]return response_contentspell_checker = SpellChecker()def check_spelling_interface(text):return spell_checker.check_spelling(text)with gr.Blocks(title="中文錯字檢查") as demo:gr.Markdown("# 中文錯字檢查")input_text = gr.Textbox(placeholder="輸入全文...", label="你的文本", lines=10)check_button = gr.Button("檢查錯字")output_text = gr.Textbox(label="錯字列表", lines=10)check_button.click(check_spelling_interface, inputs=input_text, outputs=output_text)demo.launch(share=True)
app.py+25-31