Spaces:
Sleeping
Sleeping
Commit ·
cd3cabd
1
Parent(s): 26a2965
First commit to see interfaz
Browse files- src/streamlit_app.py +6 -28
- src/utils.py +39 -0
src/streamlit_app.py
CHANGED
|
@@ -4,37 +4,15 @@ import pandas as pd
|
|
| 4 |
import streamlit as st
|
| 5 |
|
| 6 |
"""
|
| 7 |
-
#
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
forums](https://discuss.streamlit.io).
|
| 12 |
|
| 13 |
-
|
| 14 |
-
"""
|
| 15 |
-
|
| 16 |
-
num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
|
| 17 |
-
num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
|
| 18 |
|
| 19 |
-
|
| 20 |
-
theta = 2 * np.pi * num_turns * indices
|
| 21 |
-
radius = indices
|
| 22 |
|
| 23 |
-
|
| 24 |
-
y = radius * np.sin(theta)
|
| 25 |
|
| 26 |
-
df = pd.DataFrame({
|
| 27 |
-
"x": x,
|
| 28 |
-
"y": y,
|
| 29 |
-
"idx": indices,
|
| 30 |
-
"rand": np.random.randn(num_points),
|
| 31 |
-
})
|
| 32 |
|
| 33 |
-
st.altair_chart(alt.Chart(df, height=700, width=700)
|
| 34 |
-
.mark_point(filled=True)
|
| 35 |
-
.encode(
|
| 36 |
-
x=alt.X("x", axis=None),
|
| 37 |
-
y=alt.Y("y", axis=None),
|
| 38 |
-
color=alt.Color("idx", legend=None, scale=alt.Scale()),
|
| 39 |
-
size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
|
| 40 |
-
))
|
|
|
|
| 4 |
import streamlit as st
|
| 5 |
|
| 6 |
"""
|
| 7 |
+
# Bienvenido a tu Tutor IA
|
| 8 |
|
| 9 |
+
Este ChatBot está diseñado para ayudarte a aprender y practicar tus habilidades en matemáticas y física.
|
| 10 |
+
Puedes hacer preguntas, resolver problemas y recibir explicaciones detalladas sobre diversos temas.
|
|
|
|
| 11 |
|
| 12 |
+
## !Empecemos!
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
"""
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
st.title("Bienvenido a tu Tutor IA. ¡Espero que hoy estés lleno de curiosidad y ganas de aprender!.")
|
|
|
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/utils.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
from langchain_huggingface import HuggingFacePipeline
|
| 3 |
+
from langchain.prompts import PromptTemplate
|
| 4 |
+
from transformers.utils.logging import set_verbosity_error
|
| 5 |
+
|
| 6 |
+
## setup the model
|
| 7 |
+
set_verbosity_error()
|
| 8 |
+
|
| 9 |
+
# Use Phi-2 for math solving
|
| 10 |
+
math_pipeline = pipeline(
|
| 11 |
+
"text-generation",
|
| 12 |
+
model="microsoft/phi-2", # hjskhan/gemma-2b-fine-tuned-math
|
| 13 |
+
device=0,
|
| 14 |
+
max_new_tokens=256, # 💡 increase for full explanation
|
| 15 |
+
temperature=0.7,
|
| 16 |
+
do_sample=True
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
math_solver = HuggingFacePipeline(pipeline=math_pipeline)
|
| 20 |
+
|
| 21 |
+
# QA model (same as before)
|
| 22 |
+
qa_pipeline = pipeline("question-answering", model="bert-large-uncased-whole-word-masking-finetuned-squad", device=-1)
|
| 23 |
+
|
| 24 |
+
# Prompt to force step-by-step reasoning
|
| 25 |
+
math_template = PromptTemplate.from_template(
|
| 26 |
+
"You are a math and physics tutor with great didactic methods. Solve the following problem step-by-step and explain clearly:\n\n{problem}\n\nSolution:"
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
# Chain definition
|
| 30 |
+
math_chain = math_template | math_solver
|
| 31 |
+
|
| 32 |
+
def ask_math_problem(problem):
|
| 33 |
+
"""
|
| 34 |
+
Function to ask a math problem and get the solution.
|
| 35 |
+
"""
|
| 36 |
+
# Generate the answer
|
| 37 |
+
solution = math_chain.invoke({"problem": problem})
|
| 38 |
+
|
| 39 |
+
return solution
|