jchen8000 commited on
Commit
23a61ed
·
verified ·
1 Parent(s): c1c81d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -34
app.py CHANGED
@@ -78,41 +78,41 @@ def load_sample_pdf():
78
  return "Sample PDF indexed successfully!"
79
 
80
 
81
- def format_docs(docs):
82
- return "\n\n".join(doc.page_content for doc in docs)
83
 
84
 
85
- def generate_response(query, history, model, temperature, max_tokens, top_p, seed):
86
- if vector_store is None:
87
- return "Please upload and index a PDF at the Indexing tab."
88
 
89
- if seed == 0:
90
- seed = random.randint(1, 100000)
91
 
92
- retriever = vector_store.as_retriever(search_type="similarity", search_kwargs={"k": 16})
93
- llm = ChatGroq(groq_api_key=os.environ.get("GROQ_API_KEY"), model=model)
94
- custom_rag_prompt = PromptTemplate.from_template(template)
95
 
96
- rag_chain = (
97
- {"context": retriever | format_docs, "question": RunnablePassthrough()}
98
- | custom_rag_prompt
99
- | llm
100
- | StrOutputParser()
101
- )
102
-
103
- response = rag_chain.invoke(query)
104
 
105
- return response
106
 
107
 
108
 
109
- additional_inputs = [
110
- gr.Dropdown(choices=["llama-3.1-70b-versatile", "llama-3.1-8b-instant", "llama3-70b-8192", "llama3-8b-8192", "mixtral-8x7b-32768", "gemma2-9b-it", "gemma-7b-it"], value="llama-3.1-70b-versatile", label="Model"),
111
- gr.Slider(minimum=0.0, maximum=1.0, step=0.01, value=0.5, label="Temperature", info="Controls diversity of the generated text. Lower is more deterministic, higher is more creative."),
112
- gr.Slider(minimum=1, maximum=8000, step=1, value=8000, label="Max Tokens", info="The maximum number of tokens that the model can process in a single response.<br>Maximums: 8k for gemma 7b it, gemma2 9b it, llama 7b & 70b, 32k for mixtral 8x7b, 132k for llama 3.1."),
113
- gr.Slider(minimum=0.0, maximum=1.0, step=0.01, value=0.5, label="Top P", info="A method of text generation where a model will only consider the most probable next tokens that make up the probability p."),
114
- gr.Number(precision=0, value=0, label="Seed", info="A starting point to initiate generation, use 0 for random")
115
- ]
116
 
117
  # Create the Gradio interface
118
  with gr.Blocks(theme="Nymbo/Alyx_Theme") as demo:
@@ -125,14 +125,14 @@ with gr.Blocks(theme="Nymbo/Alyx_Theme") as demo:
125
  index_button.click(index_pdf, inputs=pdf_input, outputs=index_output)
126
  load_sample.click(load_sample_pdf, inputs=None, outputs=index_output)
127
 
128
- with gr.Tab("Chatbot"):
129
- gr.ChatInterface(
130
- fn=generate_response,
131
- chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
132
- examples=examples_questions,
133
- additional_inputs=additional_inputs,
134
- cache_examples=False,
135
- )
136
 
137
  # Launch the Gradio app
138
  demo.launch()
 
78
  return "Sample PDF indexed successfully!"
79
 
80
 
81
+ # def format_docs(docs):
82
+ # return "\n\n".join(doc.page_content for doc in docs)
83
 
84
 
85
+ # def generate_response(query, history, model, temperature, max_tokens, top_p, seed):
86
+ # if vector_store is None:
87
+ # return "Please upload and index a PDF at the Indexing tab."
88
 
89
+ # if seed == 0:
90
+ # seed = random.randint(1, 100000)
91
 
92
+ # retriever = vector_store.as_retriever(search_type="similarity", search_kwargs={"k": 16})
93
+ # llm = ChatGroq(groq_api_key=os.environ.get("GROQ_API_KEY"), model=model)
94
+ # custom_rag_prompt = PromptTemplate.from_template(template)
95
 
96
+ # rag_chain = (
97
+ # {"context": retriever | format_docs, "question": RunnablePassthrough()}
98
+ # | custom_rag_prompt
99
+ # | llm
100
+ # | StrOutputParser()
101
+ # )
102
+
103
+ # response = rag_chain.invoke(query)
104
 
105
+ # return response
106
 
107
 
108
 
109
+ # additional_inputs = [
110
+ # gr.Dropdown(choices=["llama-3.1-70b-versatile", "llama-3.1-8b-instant", "llama3-70b-8192", "llama3-8b-8192", "mixtral-8x7b-32768", "gemma2-9b-it", "gemma-7b-it"], value="llama-3.1-70b-versatile", label="Model"),
111
+ # gr.Slider(minimum=0.0, maximum=1.0, step=0.01, value=0.5, label="Temperature", info="Controls diversity of the generated text. Lower is more deterministic, higher is more creative."),
112
+ # gr.Slider(minimum=1, maximum=8000, step=1, value=8000, label="Max Tokens", info="The maximum number of tokens that the model can process in a single response.<br>Maximums: 8k for gemma 7b it, gemma2 9b it, llama 7b & 70b, 32k for mixtral 8x7b, 132k for llama 3.1."),
113
+ # gr.Slider(minimum=0.0, maximum=1.0, step=0.01, value=0.5, label="Top P", info="A method of text generation where a model will only consider the most probable next tokens that make up the probability p."),
114
+ # gr.Number(precision=0, value=0, label="Seed", info="A starting point to initiate generation, use 0 for random")
115
+ # ]
116
 
117
  # Create the Gradio interface
118
  with gr.Blocks(theme="Nymbo/Alyx_Theme") as demo:
 
125
  index_button.click(index_pdf, inputs=pdf_input, outputs=index_output)
126
  load_sample.click(load_sample_pdf, inputs=None, outputs=index_output)
127
 
128
+ # with gr.Tab("Chatbot"):
129
+ # gr.ChatInterface(
130
+ # fn=generate_response,
131
+ # chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
132
+ # examples=examples_questions,
133
+ # additional_inputs=additional_inputs,
134
+ # cache_examples=False,
135
+ # )
136
 
137
  # Launch the Gradio app
138
  demo.launch()