import gradio as gr from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline import torch # ✅ نموذج خفيف مناسب لـ CPU model_id = "bert-base-multilingual-cased" # ✅ تحميل النموذج والتوكن tokenizer = AutoTokenizer.from_pretrained(model_id) model = AutoModelForCausalLM.from_pretrained( model_id, torch_dtype=torch.float32, #device_map="cpu" ) # ✅ إعداد pipeline النصي generator = pipeline( "text-generation", model=model, tokenizer=tokenizer, max_new_tokens=256, temperature=0.7, return_full_text=False ) SYSTEM_PROMPT = """ You are an expert business analyst. Your task is to classify the business idea as either: 1. Startup: Innovative, scalable, tech-driven concept targeting rapid growth and unconventional funding. 2. Traditional Business: Conventional model focusing on local markets with traditional funding sources. Provide only: 1. Classification: "Startup" or "Traditional Business" 2. Reason: A brief 1-2 sentence explanation of your decision Focus specifically on whether the idea shows: - High innovation and scalability (Startup) - Conventional approach with local focus (Traditional Business) Example Response: "Classification: Startup Reason: This AI-powered platform demonstrates high innovation and scalability potential with its technology-driven solution targeting global markets." """ # ✅ دالة التحليل def analyze_idea(user_input): try: full_prompt = f"{SYSTEM_PROMPT}\n\nUser's idea: {user_input}" output = generator(full_prompt)[0]['generated_text'] return output.strip() except Exception as e: return f"❌ Error analyzing idea:\n{str(e)}" # ✅ واجهة Gradio iface = gr.Interface( fn=analyze_idea, inputs=gr.Textbox(lines=5, label="💡 Enter your business idea"), outputs=gr.Textbox(label="📊 Analysis & Classification"), title="🚀 Is Your Idea a Startup or Traditional?", description="Describe your business idea. This smart assistant will classify it and give you insights based on growth, innovation, tech-dependency, and more.", theme="default", # بإمكانك تجربة "soft" أو "huggingface" allow_flagging="never" ) iface.launch()