import gradio as gr from groq import Groq from transformers import TextStreamer client = Groq( api_key=("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"), ) def generate_response(input_text): chat_completion = client.chat.completions.create( messages=[ { "role": "user", "content": input_text, } ], model="llama3-8b-8192", ) streamer = TextStreamer(client=client) response = "" for chunk in chat_completion.choices[0].message.content: response += chunk streamer.write(response) return response custom_css = """ body { background-color: #f4f4f4; font-family: 'Arial', sans-serif; color: #333; } h1 { color: #007bff; } .gradio-container { border-radius: 15px; padding: 20px; background-color: white; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); } input[type="text"] { border-radius: 10px; border: 1px solid #ccc; padding: 10px; width: 100%; } button { background-color: #007bff; color: white; border: none; padding: 10px 20px; border-radius: 10px; cursor: pointer; font-size: 16px; } button:hover { background-color: #0056b3; } """ iface = gr.Interface( fn=generate_response, inputs=gr.inputs.Textbox(lines=2, placeholder="یه چی بپرس"), outputs="text", title="💬 Parviz Chatbot", description="زنده باد", css=custom_css, theme="default", layout="vertical", allow_flagging="never" ) iface.launch()