Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import random
|
2 |
+
import requests
|
3 |
+
import gradio as gr
|
4 |
+
import os
|
5 |
+
|
6 |
+
# Define the Big Ideas and their corresponding key terms categorized by time periods
|
7 |
+
big_ideas = {
|
8 |
+
"American Identity": {
|
9 |
+
"1865-1910": ["Freedmen's Bureau", "Black Codes and Jim Crow", "The Fourteenth Amendment", "The Reconstruction Era", "The Fifteenth Amendment", "Plessy v. Ferguson", "Booker T. Washington", "W.E.B. DuBois", "Niagara Movement"],
|
10 |
+
"1910-1960": ["National Association for the Advancement of Colored People (NAACP)", "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"],
|
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 |
+
def generate_chronological_combination(big_idea):
|
36 |
+
key_terms = big_ideas[big_idea]
|
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'
|
46 |
+
headers = {
|
47 |
+
"Authorization": f"Bearer {os.environ['BEARER_TOKEN']}",
|
48 |
+
}
|
49 |
+
data = {
|
50 |
+
"model": "mistralai/Mistral-7B-Instruct-v0.2",
|
51 |
+
"max_tokens": 1024,
|
52 |
+
"temperature": 0.7,
|
53 |
+
"top_p": 0.7,
|
54 |
+
"top_k": 50,
|
55 |
+
"repetition_penalty": 1,
|
56 |
+
"stop": [
|
57 |
+
"[/INST]",
|
58 |
+
"</s>"
|
59 |
+
],
|
60 |
+
"messages": [
|
61 |
+
{
|
62 |
+
"role": "system",
|
63 |
+
"content": "You are a helpful assistant that provides insightful explanations."
|
64 |
+
},
|
65 |
+
{
|
66 |
+
"role": "user",
|
67 |
+
"content": prompt
|
68 |
+
}
|
69 |
+
]
|
70 |
+
}
|
71 |
+
response = requests.post(endpoint, json=data, headers=headers)
|
72 |
+
if response.status_code == 200:
|
73 |
+
return response.json()['choices'][0]['message']['content']
|
74 |
+
else:
|
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 = generate_chronological_combination(big_idea)
|
84 |
+
description = describe_progression(big_idea, combination)
|
85 |
+
return f"Generated combination for '{big_idea}': {combination}\n\n{description}"
|
86 |
+
|
87 |
+
demo = gr.Interface(
|
88 |
+
fn=generate_response,
|
89 |
+
inputs=gr.Dropdown(choices=list(big_ideas.keys()), label="Select a Big Idea"),
|
90 |
+
outputs="text",
|
91 |
+
title="U.S. History Big Ideas Progression",
|
92 |
+
description="Select a Big Idea to generate a combination of key terms and their progression throughout U.S. History.",
|
93 |
+
)
|
94 |
+
|
95 |
+
demo.launch()
|