Flaskk / app.py
Zasso-75's picture
Rename model.py to app.py
909c9e8
import streamlit as st
from transformers import BertForQuestionAnswering
model=BertForQuestionAnswering.from_pretrained("deepset/bert-base-cased-squad2")
from transformers import AutoTokenizer
from transformers import pipeline
tokenizer=AutoTokenizer.from_pretrained("deepset/bert-base-cased-squad2")
context=("""Global warming is related to the more general phenomenon of climate change, which refers to changes in the totality of attributes that define climate. In addition to changes in air temperature, climate change involves changes to precipitation patterns, winds, ocean currents, and other measures of Earth’s climate. Normally, climate change can be viewed as the combination of various natural forces occurring over diverse timescales. Since the advent of human civilization, climate change has involved an “anthropogenic,” or exclusively human-caused, element, and this anthropogenic element has become more important in the industrial period of the past two centuries. The term global warming is used specifically to refer to any warming of near-surface air during the past two centuries that can be traced to anthropogenic causes.
To define the concepts of global warming and climate change properly, it is first necessary to recognize that the climate of Earth has varied across many timescales, ranging from an individual human life span to billions of years. This variable climate history is typically classified in terms of “regimes” or “epochs.” For instance, the Pleistocene glacial epoch (about 2,600,000 to 11,700 years ago) was marked by substantial variations in the global extent of glaciers and ice sheets. These variations took place on timescales of tens to hundreds of millennia and were driven by changes in the distribution of solar radiation across Earth’s surface. The distribution of solar radiation is known as the insolation pattern, and it is strongly affected by the geometry of Earth’s orbit around the Sun and by the orientation, or tilt, of Earth’s axis relative to the direct rays of the Sun.
Worldwide, the most recent glacial period, or ice age, culminated about 21,000 years ago in what is often called the Last Glacial Maximum. During this time, continental ice sheets extended well into the middle latitude regions of Europe and North America, reaching as far south as present-day London and New York City. Global annual mean temperature appears to have been about 4–5 °C (7–9 °F) colder than in the mid-20th century. It is important to remember that these figures are a global average. In fact, during the height of this last ice age, Earth’s climate was characterized by greater cooling at higher latitudes (that is, toward the poles) and relatively little cooling over large parts of the tropical oceans (near the Equator). This glacial interval terminated abruptly about 11,700 years ago and was followed by the subsequent relatively ice-free period known as the Holocene Epoch. The modern period of Earth’s history is conventionally defined as residing within the Holocene. However, some scientists have argued that the Holocene Epoch terminated in the relatively recent past and that Earth currently resides in a climatic interval that could justly be called the Anthropocene Epoch—that is, a period during which humans have exerted a dominant influence over climate.
Though less dramatic than the climate changes that occurred during the Pleistocene Epoch, significant variations in global climate have nonetheless taken place over the course of the Holocene. During the early Holocene, roughly 9,000 years ago, atmospheric circulation and precipitation patterns appear to have been substantially different from those of today. For example, there is evidence for relatively wet conditions in what is now the Sahara Desert. The change from one climatic regime to another was caused by only modest changes in the pattern of insolation within the Holocene interval as well as the interaction of these patterns with large-scale climate phenomena such as monsoons and El Niño/Southern Oscillation (ENSO).
During the middle Holocene, some 5,000–7,000 years ago, conditions appear to have been relatively warm—indeed, perhaps warmer than today in some parts of the world and during certain seasons. For this reason, this interval is sometimes referred to as the Mid-Holocene Climatic Optimum. The relative warmth of average near-surface air temperatures at this time, however, is somewhat unclear. Changes in the pattern of insolation favoured warmer summers at higher latitudes in the Northern Hemisphere, but these changes also produced cooler winters in the Northern Hemisphere and relatively cool conditions year-round in the tropics. Any overall hemispheric or global mean temperature changes thus reflected a balance between competing seasonal and regional changes. In fact, recent theoretical climate model studies suggest that global mean temperatures during the middle Holocene were probably 0.2–0.3 °C (0.4–0.5 °F) colder than average late 20th-century conditions.
Over subsequent millennia, conditions appear to have cooled relative to middle Holocene levels. This period has sometimes been referred to as the “Neoglacial.” In the middle latitudes this cooling trend was associated with intermittent periods of advancing and retreating mountain glaciers reminiscent of (though far more modest than) the more substantial advance and retreat of the major continental ice sheets of the Pleistocene climate epoch.
Causes of global warming
The greenhouse effect
The average surface temperature of Earth is maintained by a balance of various forms of solar and terrestrial radiation. Solar radiation is often called “shortwave” radiation because the frequencies of the radiation are relatively high and the wavelengths relatively short—close to the visible portion of the electromagnetic spectrum. Terrestrial radiation, on the other hand, is often called “longwave” radiation because the frequencies are relatively low and the wavelengths relatively long—somewhere in the infrared part of the spectrum. Downward-moving solar energy is typically measured in watts per square metre. The energy of the total incoming solar radiation at the top of Earth’s atmosphere (the so-called “solar constant”) amounts roughly to 1,366 watts per square metre annually. Adjusting for the fact that only one-half of the planet’s surface receives solar radiation at any given time, the average surface insolation is 342 watts per square metre annually.
The amount of solar radiation absorbed by Earth’s surface is only a small fraction of the total solar radiation entering the atmosphere. For every 100 units of incoming solar radiation, roughly 30 units are reflected back to space by either clouds, the atmosphere, or reflective regions of Earth’s surface. This reflective capacity is referred to as Earth’s planetary albedo, and it need not remain fixed over time, since the spatial extent and distribution of reflective formations, such as clouds and ice cover, can change. The 70 units of solar radiation that are not reflected may be absorbed by the atmosphere, clouds, or the surface. In the absence of further complications, in order to maintain thermodynamic equilibrium, Earth’s surface and atmosphere must radiate these same 70 units back to space. Earth’s surface temperature (and that of the lower layer of the atmosphere essentially in contact with the surface) is tied to the magnitude of this emission of outgoing radiation according to the Stefan-Boltzmann law.""")
question=st.text_area("enter question")
if text:
#tokenizer.encode(question,truncation=True,padding=True)
nlp=pipeline ("question-answering",model=model,tokenizer=tokenizer)
output=nlp({
'question':question,
'context':context
})
out=output['answer']
st.json(out)
"""import pickle
pickle.dump(nlp,open('nlp_model.pkl','wb'))"""