yilunzhao commited on
Commit
46e0b73
·
verified ·
1 Parent(s): 68158b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -36
app.py CHANGED
@@ -4,7 +4,10 @@ from openai import OpenAI
4
 
5
  # ----------------------- CONSTANTS ----------------------- #
6
  SYSTEM_PROMPT = """
7
- Given the research context, design an ablation study for the specified module or process.\nBegin the design with a clear statement of the research objective, followed by a detailed description of the experiment setup.\nDo not include the discussion of results or conclusions in the response, as the focus is solely on the experimental design.\nThe response should be within 300 words. Present the response in **Markdown** format (use headings, bold text, and bullet or numbered lists where appropriate).
 
 
 
8
  """.strip()
9
 
10
  # ----------------------- HELPERS ------------------------- #
@@ -41,12 +44,12 @@ def generate_ablation_design(
41
  module_name,
42
  api_key,
43
  ):
44
- """Combine inputs ➜ call OpenAI ➜ return the ablation-study design text (Markdown)."""
45
- # 1 ) validate the API key
46
  if not api_key or not api_key.startswith("sk-"):
47
  return "❌ **Please enter a valid OpenAI API key in the textbox above.**"
48
 
49
- # 2 ) build the chat conversation
50
  messages = [
51
  {"role": "system", "content": SYSTEM_PROMPT},
52
  {
@@ -61,7 +64,7 @@ def generate_ablation_design(
61
  },
62
  ]
63
 
64
- # 3 ) call the model
65
  client = OpenAI(api_key=api_key)
66
  try:
67
  response = client.chat.completions.create(
@@ -76,41 +79,48 @@ def generate_ablation_design(
76
 
77
  # ----------------------- UI LAYOUT ----------------------- #
78
  with gr.Blocks(title="Ablation Study Designer") as demo:
79
- gr.Markdown(
80
- """
81
- # 🧪 Ablation Study Designer \n
82
- Supply your study details below, then click **Generate** to receive a tailored ablation-study design rendered in Markdown.
83
- """
84
- )
 
 
 
 
 
85
 
86
- # API-key field (required)
87
- api_key = gr.Textbox(
88
- label="🔑 OpenAI API Key (required)",
89
- type="password",
90
- placeholder="sk-...",
91
- )
92
 
93
- research_background = gr.Textbox(
94
- label="Research Background", lines=6, placeholder="Describe the broader research context…"
95
- )
96
- method = gr.Textbox(
97
- label="Method Description", lines=6, placeholder="Summarize the method section…"
98
- )
99
- experiment_setup = gr.Textbox(
100
- label="Main Experiment – Setup", lines=6, placeholder="Datasets, hyper-parameters, etc."
101
- )
102
- experiment_results = gr.Textbox(
103
- label="Main Experiment – Results", lines=6, placeholder="Key quantitative or qualitative findings…"
104
- )
105
- module_name = gr.Textbox(
106
- label="Module / Process for Ablation", placeholder="e.g., Attention mechanism"
107
- )
108
 
109
- generate_btn = gr.Button("Generate Ablation Study Design")
110
 
111
- # Markdown output area dynamic, renders Markdown
112
- output_md = gr.Markdown(value="", label="Ablation Study Design")
 
113
 
 
114
  generate_btn.click(
115
  fn=generate_ablation_design,
116
  inputs=[
@@ -122,8 +132,9 @@ with gr.Blocks(title="Ablation Study Designer") as demo:
122
  api_key,
123
  ],
124
  outputs=output_md,
 
125
  )
126
 
127
  # ----------------------- LAUNCH -------------------------- #
128
  if __name__ == "__main__":
129
- demo.launch()
 
4
 
5
  # ----------------------- CONSTANTS ----------------------- #
6
  SYSTEM_PROMPT = """
7
+ Given the research context, design an ablation study for the specified module or process.
8
+ Begin the design with a clear statement of the research objective, followed by a detailed description of the experiment setup.
9
+ Do not include the discussion of results or conclusions in the response, as the focus is solely on the experimental design.
10
+ The response should be within 300 words. Present the response in **Markdown** format (use headings, bold text, and bullet or numbered lists where appropriate).
11
  """.strip()
12
 
13
  # ----------------------- HELPERS ------------------------- #
 
44
  module_name,
45
  api_key,
46
  ):
47
+ """Combine inputs ➜ call OpenAI ➜ return the ablationstudy design text (Markdown)."""
48
+ # 1) Validate the API key format.
49
  if not api_key or not api_key.startswith("sk-"):
50
  return "❌ **Please enter a valid OpenAI API key in the textbox above.**"
51
 
52
+ # 2) Build the chat conversation payload.
53
  messages = [
54
  {"role": "system", "content": SYSTEM_PROMPT},
55
  {
 
64
  },
65
  ]
66
 
67
+ # 3) Call the model and return the assistant response.
68
  client = OpenAI(api_key=api_key)
69
  try:
70
  response = client.chat.completions.create(
 
79
 
80
  # ----------------------- UI LAYOUT ----------------------- #
81
  with gr.Blocks(title="Ablation Study Designer") as demo:
82
+ # Main two‑column layout.
83
+ with gr.Row():
84
+ # ---------- LEFT COLUMN: INPUTS ----------
85
+ with gr.Column(scale=1):
86
+ gr.Markdown(
87
+ """
88
+ # 🧪 Ablation Study Designer
89
+ Fill in the study details below, then click **Generate** to receive a tailored ablation‑study design rendered in Markdown.
90
+ """,
91
+ elem_id="header",
92
+ )
93
 
94
+ # APIkey field (required)
95
+ api_key = gr.Textbox(
96
+ label="🔑 OpenAI API Key (required)",
97
+ type="password",
98
+ placeholder="sk-...",
99
+ )
100
 
101
+ research_background = gr.Textbox(
102
+ label="Research Background", lines=6, placeholder="Describe the broader research context…"
103
+ )
104
+ method = gr.Textbox(
105
+ label="Method Description", lines=6, placeholder="Summarize the method section…"
106
+ )
107
+ experiment_setup = gr.Textbox(
108
+ label="Main Experiment – Setup", lines=6, placeholder="Datasets, hyperparameters, etc."
109
+ )
110
+ experiment_results = gr.Textbox(
111
+ label="Main Experiment – Results", lines=6, placeholder="Key quantitative or qualitative findings…"
112
+ )
113
+ module_name = gr.Textbox(
114
+ label="Module / Process for Ablation", placeholder="e.g., Attention mechanism"
115
+ )
116
 
117
+ generate_btn = gr.Button("Generate Ablation Study Design")
118
 
119
+ # ---------- RIGHT COLUMN: OUTPUT ----------
120
+ with gr.Column(scale=1):
121
+ output_md = gr.Markdown(value="", label="Ablation Study Design")
122
 
123
+ # Button click: trigger generation with a loading indicator.
124
  generate_btn.click(
125
  fn=generate_ablation_design,
126
  inputs=[
 
132
  api_key,
133
  ],
134
  outputs=output_md,
135
+ show_progress="full", # Display a full‑screen progress bar.
136
  )
137
 
138
  # ----------------------- LAUNCH -------------------------- #
139
  if __name__ == "__main__":
140
+ demo.launch()