Spaces:
Sleeping
Sleeping
test
Browse filesFiles changed (5)
- .gitignoreAdded+176
- app.pyAdded+109
- prompts/initial_prompt.pyAdded+6
- prompts/main_prompt.pyAdded+64
- requirements.txtAdded+3
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176.env
# Byte-compiled / optimized / DLL files__pycache__/*.py[cod]*$py.class
# C extensions*.so
# Distribution / packaging.Pythonbuild/develop-eggs/dist/downloads/eggs/.eggs/lib/lib64/parts/sdist/var/wheels/share/python-wheels/*.egg-info/.installed.cfg*.eggMANIFEST
# PyInstaller# Usually these files are written by a python script from a template# before PyInstaller builds the exe, so as to inject date/other infos into it.*.manifest*.spec
# Installer logspip-log.txtpip-delete-this-directory.txt
# Unit test / coverage reportshtmlcov/.tox/.nox/.coverage.coverage.*.cachenosetests.xmlcoverage.xml*.cover*.py,cover.hypothesis/.pytest_cache/cover/
# Translations*.mo*.pot
# Django stuff:*.loglocal_settings.pydb.sqlite3db.sqlite3-journal
# Flask stuff:instance/.webassets-cache
# Scrapy stuff:.scrapy
# Sphinx documentationdocs/_build/
# PyBuilder.pybuilder/target/
# Jupyter Notebook.ipynb_checkpoints
# IPythonprofile_default/ipython_config.py
# pyenv# For a library or package, you might want to ignore these files since the code is# intended to run in multiple environments; otherwise, check them in:# .python-version
# pipenv# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.# However, in case of collaboration, if having platform-specific dependencies or dependencies# having no cross-platform support, pipenv may install dependencies that don't work, or not# install all needed dependencies.#Pipfile.lock
# UV# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.# This is especially recommended for binary packages to ensure reproducibility, and is more# commonly ignored for libraries.#uv.lock
# poetry# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.# This is especially recommended for binary packages to ensure reproducibility, and is more# commonly ignored for libraries.# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control#poetry.lock
# pdm# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.#pdm.lock# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it# in version control.# https://pdm.fming.dev/latest/usage/project/#working-with-version-control.pdm.toml.pdm-python.pdm-build/
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm__pypackages__/
# Celery stuffcelerybeat-schedulecelerybeat.pid
# SageMath parsed files*.sage.py
# Environments.env.venvenv/venv/ENV/env.bak/venv.bak/
# Spyder project settings.spyderproject.spyproject
# Rope project settings.ropeproject
# mkdocs documentation/site
# mypy.mypy_cache/.dmypy.jsondmypy.json
# Pyre type checker.pyre/
# pytype static type analyzer.pytype/
# Cython debug symbolscython_debug/
# PyCharm# JetBrains specific template is maintained in a separate JetBrains.gitignore that can# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore# and can be added to the global gitignore or merged into this file. For a more nuclear# option (not recommended) you can uncomment the following to ignore the entire idea folder.#.idea/
# Ruff stuff:.ruff_cache/
# PyPI configuration file.pypirc123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109import osimport gradio as grfrom dotenv import load_dotenvfrom openai import OpenAIfrom prompts.initial_prompt import INITIAL_PROMPTfrom prompts.main_prompt import MAIN_PROMPT
# .env ํ์ผ์์ OPENAI_API_KEY ๋ก๋if os.path.exists(".env"): load_dotenv(".env")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
client = OpenAI(api_key=OPENAI_API_KEY)
def gpt_call(history, user_message, model="gpt-4o-mini", max_tokens=512, temperature=0.7, top_p=0.95): """ OpenAI ChatCompletion API๋ฅผ ํตํด ๋ต๋ณ์ ์์ฑํ๋ ํจ์. - history: [(user_text, assistant_text), ...] - user_message: ์ฌ์ฉ์๊ฐ ๋ฐฉ๊ธ ์
๋ ฅํ ๋ฉ์์ง """ # 1) ์์คํ
๋ฉ์์ง(=MAIN_PROMPT)๋ฅผ ๊ฐ์ฅ ์์ ์ถ๊ฐ messages = [{"role": "system", "content": MAIN_PROMPT}] # 2) ๊ธฐ์กด ๋ํ ๊ธฐ๋ก(history)์ OpenAI ํ์์ผ๋ก ๋ณํ # user_text -> 'user' / assistant_text -> 'assistant' for user_text, assistant_text in history: if user_text: messages.append({"role": "user", "content": user_text}) if assistant_text: messages.append({"role": "assistant", "content": assistant_text})
# 3) ๋ง์ง๋ง์ ์ด๋ฒ ์ฌ์ฉ์์ ์
๋ ฅ์ ์ถ๊ฐ messages.append({"role": "user", "content": user_message})
# 4) OpenAI API ํธ์ถ completion = client.chat.completions.create( model=model, messages=messages, max_tokens=max_tokens, temperature=temperature, top_p=top_p ) return completion.choices[0].message.content
def respond(user_message, history): """ Gradio ์์์ submitํ ๋ ํธ์ถ๋๋ ํจ์ - user_message: ์ฌ์ฉ์๊ฐ ๋ฐฉ๊ธ ์น ๋ฉ์์ง - history: ๊ธฐ์กด (user, assistant) ํํ ๋ฆฌ์คํธ """ # ์ฌ์ฉ์๊ฐ ๋น ๋ฌธ์์ด์ ๋ณด๋๋ค๋ฉด ์๋ฌด ์ผ๋ ํ์ง ์์ if not user_message: return "", history
# GPT ๋ชจ๋ธ๋ก๋ถํฐ ์๋ต์ ๋ฐ์ assistant_reply = gpt_call(history, user_message)
# history์ (user, assistant) ์ ์ถ๊ฐ history.append((user_message, assistant_reply))
# Gradio์์๋ (์๋ก ๋น์์ง ์
๋ ฅ์ฐฝ, ๊ฐฑ์ ๋ history)๋ฅผ ๋ฐํ return "", history
############################### Gradio Blocks UI##############################with gr.Blocks() as demo: gr.Markdown("## Simple Chat Interface")
# Chatbot ์ด๊ธฐ ์ํ๋ฅผ ์ค์ # ์ฒซ ๋ฒ์งธ ๋ฉ์์ง๋ (user="", assistant=INITIAL_PROMPT) ํํ๋ก ๋ฃ์ด # ํ๋ฉด์์์ 'assistant'๊ฐ INITIAL_PROMPT๋ฅผ ๋งํ ๊ฒ์ฒ๋ผ ๋ณด์ด๊ฒ ํจ chatbot = gr.Chatbot( value=[("", INITIAL_PROMPT)], # (user, assistant) height=500 )
# (user, assistant) ์์ ์ ์ฅํ ํ์คํ ๋ฆฌ ์ํ # ์ฌ๊ธฐ์๋ ๋์ผํ ์ด๊ธฐ ์ํ๋ฅผ ๋ฃ์ด์ค state_history = gr.State([("", INITIAL_PROMPT)])
# ์ฌ์ฉ์ ์
๋ ฅ user_input = gr.Textbox( placeholder="Type your message here...", label="Your Input" )
# ์
๋ ฅ์ด submit๋๋ฉด respond() ํธ์ถ โ ์ถ๋ ฅ์ (์ ์
๋ ฅ์ฐฝ, ๊ฐฑ์ ๋ chatbot) user_input.submit( respond, inputs=[user_input, state_history], outputs=[user_input, chatbot] ).then( # respond ๋๋ ๋ค, ์ต์ history๋ฅผ state_history์ ๋ฐ์ fn=lambda _, h: h, inputs=[user_input, chatbot], outputs=[state_history] )
# ๋ฉ์ธ ์คํif __name__ == "__main__": demo.launch(server_name="0.0.0.0", server_port=7860, share=True)123456INITIAL_PROMPT = """Welcome to this module on proportional reasoning and creativity in mathematics! \Your goal is to determine which section is more crowded based on the classroom data provided. \Try to use as many methods as possible and explain your reasoning after each solution. \Letโs begin!"""12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364MAIN_PROMPT = """Module 1: Solving Problems with Multiple Solutions Through AIPrompts:Initial Introduction by AI"Welcome to this module on proportional reasoning and creativity in mathematics! Your goal is to determine which section is more crowded based on the classroom data provided. Try to use as many methods as possible and explain your reasoning after each solution. Letโs begin!"Step-by-Step Prompts with Adaptive HintsSolution 1: Comparing Ratios (Students to Capacity)"What about comparing the ratio of students to total capacity for each section? How might that help you determine which section is more crowded?"If no response: "For Section 1, the ratio is 18/34. What do you think the ratio is for Section 2?"If incorrect: "It seems like thereโs a small mistake in your calculation. Try dividing 14 by 30 for Section 2. What result do you get?"If correct: "Great! Now that youโve calculated the ratios, which one is larger, and what does that tell you about crowding?"Solution 2: Comparing Ratios (Students to Available Seats)"Have you considered looking at the ratio of students to available seats? For example, in Section 1, there are 18 students and 16 available seats. What would the ratio be for Section 2?"If no response: "Think about how you can compare the number of students to the seats left in each section. How does this ratio give insight into the crowding?"If incorrect: "Check your numbers againโhow many seats are available in Section 2? Now divide the students by that number. What does the ratio show?"If correct: "Excellent! The ratio for Section 1 is greater than 1, while itโs less than 1 for Section 2. What does that tell you about which section is more crowded?"Solution 3: Decimal Conversion"What happens if you convert the ratios into decimals? How might that make it easier to compare the sections?"If no response: "To convert the ratios into decimals, divide the number of students by the total capacity. For Section 1, divide 18 by 34. What do you get?"If incorrect: "Double-check your calculation. For Section 1, dividing 18 by 34 gives approximately 0.53. What do you think the decimal for Section 2 would be?"If correct: "Thatโs right! Comparing 0.53 for Section 1 to 0.47 for Section 2 shows which section is more crowded. Great job!"Solution 4: Percentages"What about converting the ratios into percentages? How might percentages help clarify the problem?"If no response: "Multiply the ratio by 100 to convert it into a percentage. For Section 1, (18/34) ร 100 gives what result?"If incorrect: "Letโs try that again. Dividing 18 by 34 and multiplying by 100 gives 52.94%. What percentage do you get for Section 2?"If correct: "Nice work! Comparing 52.94% for Section 1 to 46.67% for Section 2 shows that Section 1 is more crowded. Well done!"Solution 5: Visual Representation"Sometimes drawing a diagram or picture helps make things clearer. How might you visually represent the seats and students for each section?"If no response: "Try sketching out each section as a set of seats, shading the filled ones. What do you notice when you compare the two diagrams?"If incorrect or unclear: "In your diagram, did you show that Section 1 has 18 filled seats out of 34, and Section 2 has 14 filled seats out of 30? How does the shading compare between the two?"If correct: "Great visualization! Your diagram clearly shows that Section 1 is more crowded. Nice work!"Feedback Prompts for Missing or Overlooked Methods"Youโve explored a few great strategies so far. What about trying percentages or decimals next? How might those approaches provide new insights?""It looks like youโre on the right track! Have you considered drawing a picture or diagram? Visual representations can sometimes reveal patterns we donโt see in the numbers."Encouragement for Correct Solutions"Fantastic work! Youโve explained your reasoning well and explored multiple strategies. Letโs move on to another method to deepen your understanding.""Youโre doing great! Exploring different approaches is an essential part of proportional reasoning. Keep up the excellent work!"Hints for Incorrect or Incomplete Solutions"It seems like thereโs a small mistake in your calculation. Letโs revisit the ratiosโare you dividing the correct numbers?""Thatโs an interesting approach! How might converting your results into decimals or percentages clarify your comparison?""Your reasoning is on the right track, but what happens if you include another method, like drawing a diagram? Letโs explore that idea."Comparing and Connecting SolutionsPrompt to Compare Student Solutions"Student 1 said, 'Section 1 is more crowded because 18 students is more than 14 students.' Student 2 said, 'Section 1 is more crowded because it is more than half full.' Which reasoning aligns better with proportional reasoning, and why?"Feedback for Absolute vs. Relative Thinking"Focusing on absolute numbers is a good start, but proportional reasoning involves comparing relationships, like ratios or percentages. How can you guide students to think in terms of ratios rather than raw numbers?"Reflection and Common Core ConnectionsConnecting Creativity-Directed Practices"Which creativity-directed practices did you engage in while solving this problem? Examples include using multiple solution methods, visualizing ideas, and making generalizations. How do these practices support student engagement?"Common Core Standards Alignment*"Which Common Core Mathematical Practice Standards do you think apply to this task? Examples include:Make sense of problems and persevere in solving them.Reason abstractly and quantitatively."*If they miss a key standard:"Did this task require you to analyze the ratios and interpret their meaning? That aligns with Standard #2, Reason Abstractly and Quantitatively. Can you see how that applies here?""How might engaging students in this task encourage productive struggle (#1)? What strategies could you use to support students in persevering through this problem?"AI Summary PromptsContent Knowledge"We explored proportional reasoning through multiple strategies: comparing ratios, converting to decimals, calculating percentages, and using visual representations. These methods deepened our understanding of ratios as relationships between quantities."Creativity-Directed Practices"We engaged in multiple solution tasks, visualized mathematical ideas, and made generalizations. These practices foster creativity and encourage students to think critically about mathematical concepts."Pedagogical Content Knowledge"You learned how to guide students from absolute thinking to relative thinking, focusing on proportional reasoning. You also saw how to connect creativity-directed practices with Common Core Standards, turning routine problems into opportunities for deeper engagement.""""123huggingface_hub==0.25.2openaipython-dotenv.gitignoreAdded+176
app.pyAdded+109
prompts/initial_prompt.pyAdded+6
prompts/main_prompt.pyAdded+64
requirements.txtAdded+3