File size: 1,862 Bytes
6dd7e02
 
 
864038d
6dd7e02
864038d
 
 
6dd7e02
864038d
 
 
 
 
6dd7e02
864038d
 
 
 
6dd7e02
864038d
 
 
 
6dd7e02
 
 
864038d
 
 
 
 
 
 
 
 
 
6dd7e02
 
 
 
 
 
 
 
 
 
 
 
 
 
864038d
6dd7e02
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import gradio as gr
import torch
from transformers import AutoTokenizer, T5ForConditionalGeneration
from peft import PeftModel

# 1. Define your models
# CHANGE THIS to the exact base model you used before fine-tuning (e.g., "t5-3b")
base_model_id = "google/flan-t5-xl" 

# Your fine-tuned repository
adapter_repo = "Spark2scale/Spark2Scale"

# 2. Load the Tokenizer
# We load this from your adapter repo to keep any special tokens you might have added
print("Loading tokenizer...")
tokenizer = AutoTokenizer.from_pretrained(
    adapter_repo, 
    subfolder="checkpoint-4000" # Add this if your files are inside a specific folder
)

# 3. Load the Base Model in bfloat16
print("Loading base model in bfloat16...")
base_model = T5ForConditionalGeneration.from_pretrained(
    base_model_id,
    torch_dtype=torch.bfloat16
)

# 4. Apply your PEFT Adapter on top of the base model
print("Applying adapter weights...")
model = PeftModel.from_pretrained(
    base_model, 
    adapter_repo,
    subfolder="checkpoint-4000" # Remove this line if the files are in the main repo root
)
model.eval()

# 5. Define the prediction function
def evaluate_idea(startup_idea):
    inputs = tokenizer(startup_idea, return_tensors="pt")
    
    with torch.no_grad():
        outputs = model.generate(
            **inputs,
            max_new_tokens=512,
            temperature=0.7,
            do_sample=True
        )
        
    result = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return result

# 6. Build and launch the Gradio Interface
iface = gr.Interface(
    fn=evaluate_idea,
    inputs=gr.Textbox(lines=5, placeholder="Enter the startup idea here...", label="Startup Idea"),
    outputs=gr.Textbox(label="Evaluation Report"),
    title="Spark2Scale Idea Evaluator",
    description="Backend API for the Spark2Scale evaluation agent."
)

iface.launch()