Dohahemdann commited on
Commit
6dd7e02
·
verified ·
1 Parent(s): 8aab78b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import AutoTokenizer, T5ForConditionalGeneration
4
+
5
+ # 1. Define your fine-tuned model
6
+ model_name = "Spark2scale/Spark2Scale"
7
+
8
+ # 2. Load the model and tokenizer
9
+ # Using bfloat16 is crucial here to fit the 3B model into the 16GB free tier
10
+ print("Loading tokenizer...")
11
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
12
+
13
+ print("Loading model in bfloat16...")
14
+ model = T5ForConditionalGeneration.from_pretrained(
15
+ model_name,
16
+ torch_dtype=torch.bfloat16
17
+ )
18
+ model.eval() # Set to evaluation mode
19
+
20
+ # 3. Define the prediction function
21
+ def evaluate_idea(startup_idea):
22
+ # Tokenize input
23
+ inputs = tokenizer(startup_idea, return_tensors="pt")
24
+
25
+ # Generate text (adjust max_new_tokens based on your desired report length)
26
+ with torch.no_grad():
27
+ outputs = model.generate(
28
+ **inputs,
29
+ max_new_tokens=512,
30
+ temperature=0.7,
31
+ do_sample=True
32
+ )
33
+
34
+ # Decode and return the result
35
+ result = tokenizer.decode(outputs[0], skip_special_tokens=True)
36
+ return result
37
+
38
+ # 4. Build the Gradio Interface
39
+ # This UI automatically generates the REST API endpoint
40
+ iface = gr.Interface(
41
+ fn=evaluate_idea,
42
+ inputs=gr.Textbox(lines=5, placeholder="Enter the startup idea here...", label="Startup Idea"),
43
+ outputs=gr.Textbox(label="Evaluation Report"),
44
+ title="Spark2Scale Idea Evaluator",
45
+ description="Backend API for the Spark2Scale evaluation agent."
46
+ )
47
+
48
+ # 5. Launch the app
49
+ iface.launch()