Update app.py
Browse files
app.py
CHANGED
@@ -3,43 +3,15 @@ import requests
|
|
3 |
import gradio as gr
|
4 |
import os
|
5 |
|
6 |
-
# Define the
|
7 |
-
|
8 |
-
"American
|
9 |
-
|
10 |
-
|
11 |
-
"1960-present": ["Letter from Birmingham Jail", "Malcolm X", "Dolores Huerta", "César Chavez", "National Farm Workers Association (NFWA)", "Chicano Movement", "Shirley Chisholm"]
|
12 |
-
},
|
13 |
-
"Labor and Technology": {
|
14 |
-
"1865-1910": ["Manifest Destiny", "Transcontinental Railroad", "Robber Barons", "Andrew Carnegie", "Social Darwinism", "John D. Rockefeller", "J. Pierpont Morgan", "Cornelius Vanderbilt", "The Gilded Age"],
|
15 |
-
"1910-1960": ["Speculation in the 1920s", "Stock market crash/Black Tuesday", "Bank runs/bank closures", "Unemployment", "Herbert Hoover's Initial Reaction", "Public Reaction to Hoover", "Bonus Army", "Reforming the Banking Crisis/Emergency Banking Act", "Relief: Employment for the Masses", "Rescuing Farms and Factories", "Regional Planning/Tennessee Valley Authority", "Wagner Act a.k.a. the National Labor Relations Act", "Women in the War: Rosie the Riveter and Beyond"],
|
16 |
-
"1960-present": ["GI Bill", "military-industrial complex", "Levittown", "baby boom"]
|
17 |
-
},
|
18 |
-
"America and the World": {
|
19 |
-
"1865-1910": ["Woodrow Wilson's Early Efforts at Foreign Policy", "Spanish-American War", "American Imperialism"],
|
20 |
-
"1910-1960": ["Neutrality", "Lusitania", "Zimmermann telegram", "Women in WWI", "African Americans in WWI", "The Atlantic Charter", "Pearl Harbor, Hawaii attack, \"A Date Which Will Live in Infamy\"", "containment", "domino theory", "Truman Doctrine", "Marshall Plan", "\"Showdown in Europe\" (Berlin blockade)", "\"To the Trenches Again\" (Korean War)", "Sputnik", "Gulf of Tonkin Resolution", "Tet Offensive", "\"My Lai\" (My Lai village massacre)", "Vietnamization", "Kent State shootings", "Pentagon Papers"],
|
21 |
-
"1960-present": ["détente", "Strategic Arms Limitation Treaty (SALT)", "9/11", "War in Afghanistan and Iraq", "USA Patriot Act", "Terrorist Surveillance Program", "Hamdan v. Rumsfeld", "Naval Base at Guantanamo Bay"]
|
22 |
-
},
|
23 |
-
"Reform and Renewal": {
|
24 |
-
"1865-1910": ["muckrakers", "Progressivism", "Alice Paul", "The Anti-Suffragist Movement"],
|
25 |
-
"1910-1960": ["Prohibition", "Nativism", "Emergency Immigration Act of 1921", "Ku Klux Klan (KKK) and the 2nd Ku Klux Klan", "Scopes Monkey Trial", "The \"New Woman\" and Flappers", "The Harlem Renaissance", "Huey Long", "Social Security Act", "Supreme Court Packing Plan", "Change in Federal Government's Scope (In the Final Analysis)"],
|
26 |
-
"1960-present": ["The Great Society", "\"Bloody Sunday\"", "counterculture", "Shirley Chisholm", "Equal Rights Amendment (ERA)", "Phyllis Schlafly", "The War on Drugs"]
|
27 |
-
},
|
28 |
-
"Self and Society": {
|
29 |
-
"1865-1910": ["Boss William Tweed", "Compromise of 1877", "yellow journalism", "Spanish American War", "Rough Riders", "Anti-Imperialist League"],
|
30 |
-
"1910-1960": ["The \"New Woman\" and Flappers", "The Harlem Renaissance", "House Un-American Activities Committee", "blacklist", "Port Huron Statement", "Betty Friedan", "Title VII of the Civil Rights Act of 1964", "National Organization for Women (NOW)", "American Indian Movement (AIM)", "Stonewall Inn", "Roe v Wade"],
|
31 |
-
"1960-present": ["Shirley Chisholm", "Equal Rights Amendment (ERA)", "Richard Nixon", "silent majority", "Nixon's Domestic Policies (\"The Domestic Nixon\")", "\"plumbers\"/Committee to Re-Elect the President (CREEP)", "Watergate break-in scandal", "Gerald R. Ford", "Ronald Reagan", "The New Right", "Reaganomics", "The Heritage Foundation", "Moral Majority"]
|
32 |
-
}
|
33 |
}
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
combination = [
|
38 |
-
random.choice(key_terms["1865-1910"]),
|
39 |
-
random.choice(key_terms["1910-1960"]),
|
40 |
-
random.choice(key_terms["1960-present"])
|
41 |
-
]
|
42 |
-
return combination
|
43 |
|
44 |
def get_llm_response(prompt):
|
45 |
endpoint = 'https://api.together.xyz/v1/chat/completions'
|
@@ -48,7 +20,7 @@ def get_llm_response(prompt):
|
|
48 |
}
|
49 |
data = {
|
50 |
"model": "mistralai/Mistral-7B-Instruct-v0.2",
|
51 |
-
"max_tokens":
|
52 |
"temperature": 0.7,
|
53 |
"top_p": 0.7,
|
54 |
"top_k": 50,
|
@@ -75,21 +47,26 @@ def get_llm_response(prompt):
|
|
75 |
raise Exception(f"API request failed with status code {response.status_code}")
|
76 |
|
77 |
def describe_progression(big_idea, combination):
|
78 |
-
prompt = f"Explain how the key terms '{combination[0]}' (1865-1910), '{combination[1]}' (1910-1960), and '{combination[2]}' (1960-present) demonstrate the progression of {big_idea} throughout U.S. History. Provide a detailed explanation for each key term, highlighting the historical context and significance, and how they collectively show the progression of the Big Idea across these time periods."
|
79 |
description = get_llm_response(prompt)
|
80 |
return description
|
81 |
|
82 |
-
def generate_response(big_idea):
|
83 |
-
combination =
|
84 |
description = describe_progression(big_idea, combination)
|
85 |
-
return f"
|
86 |
|
87 |
demo = gr.Interface(
|
88 |
fn=generate_response,
|
89 |
-
inputs=
|
|
|
|
|
|
|
|
|
|
|
90 |
outputs="text",
|
91 |
title="U.S. History Big Ideas Progression",
|
92 |
-
description="Select a Big Idea to generate a
|
93 |
)
|
94 |
|
95 |
demo.launch()
|
|
|
3 |
import gradio as gr
|
4 |
import os
|
5 |
|
6 |
+
# Define the time periods and their corresponding key terms
|
7 |
+
time_periods = {
|
8 |
+
"1865-1910": ["Freedmen's Bureau", "Black Codes and Jim Crow", "The Fourteenth Amendment", "The Reconstruction Era", "The Fifteenth Amendment", "Manifest Destiny", "Transcontinental Railroad", "\"Buffalo Soldiers\"", "Robber Barons", "Andrew Carnegie", "Social Darwinism", "John D. Rockefeller", "J. Pierpont Morgan", "Cornelius Vanderbilt", "The Gilded Age", "Boss William Tweed", "Compromise of 1877", "yellow journalism", "Spanish American War", "Rough Riders", "Anti-Imperialist League", "muckrakers", "Progressivism", "Alice Paul", "The Anti-Suffragist Movement", "Booker T. Washington", "W.E.B. DuBois", "Niagara Movement", "National Association for the Advancement of Colored People (NAACP)", "Woodrow Wilson's Early Efforts at Foreign Policy"],
|
9 |
+
"1910-1960": ["Neutrality", "Lusitania", "Zimmermann telegram", "Women in WWI", "African Americans in WWI", "Prohibition", "Nativism", "Emergency Immigration Act of 1921", "Ku Klux Klan (KKK) and the 2nd Ku Klux Klan", "Scopes Monkey Trial", "The \"New Woman\" and Flappers", "The Harlem Renaissance", "Stock market crash/Black Tuesday", "Speculation in the 1920s", "Bank runs/bank closures", "Unemployment", "Herbert Hoover's Initial Reaction", "Public Reaction to Hoover", "Bonus Army", "Reforming the Banking Crisis/Emergency Banking Act", "Fireside Chats", "Relief: Employment for the Masses", "Rescuing Farms and Factories", "Regional Planning/Tennessee Valley Authority", "Huey Long", "Social Security Act", "Wagner Act a.k.a. the National Labor Relations Act", "Supreme Court Packing Plan", "Change in Federal Government's Scope (In the Final Analysis)", "Totalitarianism & fascism in Europe", "Japan militarism", "The Atlantic Charter", "Pearl Harbor, Hawaii attack, \"A Date Which Will Live in Infamy\"", "Women in the War: Rosie the Riveter and Beyond", "African Americans and Double V", "Zoot Suit Riots/Bracero Program", "Internment", "Executive Order 9066", "containment", "domino theory", "Truman Doctrine", "Marshall Plan", "\"Showdown in Europe\" (Berlin blockade)", "House Un-American Activities Committee", "blacklist", "\"To the Trenches Again\" (Korean War)", "military-industrial complex", "Sputnik", "Levittown", "baby boom", "Sweatt v. Painter", "Alice Coachman", "Brown v. Board of Education of Topeka", "Thurgood Marshall", "Little Rock Nine", "Montgomery Bus Boycott", "Southern Christian Leadership Conference (SCLC)", "Student Nonviolent Coordinating Committee (SNCC)", "Freedom Riders", "Letter from Birmingham Jail", "Malcolm X"],
|
10 |
+
"1960-present": ["The Great Society", "\"Bloody Sunday\"", "Gulf of Tonkin Resolution", "Tet Offensive", "counterculture", "\"My Lai\" (My Lai village massacre)", "Vietnamization", "Kent State shootings", "Pentagon Papers", "Dolores Huerta", "César Chavez", "National Farm Workers Association (NFWA)", "Chicano Movement", "Port Huron Statement", "Betty Friedan", "Title VII of the Civil Rights Act of 1964", "National Organization for Women (NOW)", "American Indian Movement (AIM)", "Shirley Chisholm", "Equal Rights Amendment (ERA)", "Richard Nixon", "silent majority", "Nixon's Domestic Policies (\"The Domestic Nixon\")", "détente", "Strategic Arms Limitation Treaty (SALT)", "\"plumbers\"/Committee to Re-Elect the President (CREEP)", "Watergate break-in scandal", "Gerald R. Ford", "Ronald Reagan", "The New Right", "Reaganomics", "The Heritage Foundation", "Moral Majority", "Phyllis Schlafly", "The War on Drugs", "George W. Bush", "9/11", "War in Afghanistan and Iraq", "USA Patriot Act", "Terrorist Surveillance Program", "Hamdan v. Rumsfeld", "Naval Base at Guantanamo Bay"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
}
|
12 |
|
13 |
+
# Define the Big Ideas
|
14 |
+
big_ideas = ["American Identity", "Labor and Technology", "America and the World", "Reform and Renewal", "Self and Society"]
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
def get_llm_response(prompt):
|
17 |
endpoint = 'https://api.together.xyz/v1/chat/completions'
|
|
|
20 |
}
|
21 |
data = {
|
22 |
"model": "mistralai/Mistral-7B-Instruct-v0.2",
|
23 |
+
"max_tokens": 2048,
|
24 |
"temperature": 0.7,
|
25 |
"top_p": 0.7,
|
26 |
"top_k": 50,
|
|
|
47 |
raise Exception(f"API request failed with status code {response.status_code}")
|
48 |
|
49 |
def describe_progression(big_idea, combination):
|
50 |
+
prompt = f"Explain how the key terms '{combination[0]}' (1865-1910), '{combination[1]}' (1910-1960), and '{combination[2]}' (1960-present) demonstrate the progression and connection of {big_idea} throughout U.S. History. Provide a detailed explanation for each key term, highlighting the historical context and significance, and how they collectively show the progression of the Big Idea across these time periods."
|
51 |
description = get_llm_response(prompt)
|
52 |
return description
|
53 |
|
54 |
+
def generate_response(big_idea, term1, term2, term3):
|
55 |
+
combination = [term1, term2, term3]
|
56 |
description = describe_progression(big_idea, combination)
|
57 |
+
return f"Selected combination for '{big_idea}': {combination}\n\n{description}"
|
58 |
|
59 |
demo = gr.Interface(
|
60 |
fn=generate_response,
|
61 |
+
inputs=[
|
62 |
+
gr.Dropdown(choices=big_ideas, label="Select a Big Idea"),
|
63 |
+
gr.Dropdown(choices=time_periods["1865-1910"], label="Select a key term from 1865-1910"),
|
64 |
+
gr.Dropdown(choices=time_periods["1910-1960"], label="Select a key term from 1910-1960"),
|
65 |
+
gr.Dropdown(choices=time_periods["1960-present"], label="Select a key term from 1960-present")
|
66 |
+
],
|
67 |
outputs="text",
|
68 |
title="U.S. History Big Ideas Progression",
|
69 |
+
description="Select a Big Idea and three key terms (one from each time period) to generate a description of their progression and connection throughout U.S. History.",
|
70 |
)
|
71 |
|
72 |
demo.launch()
|