Aiteam / app.py
Shatha2030's picture
Update app.py
193c303 verified
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()