Spaces:
Runtime error
Runtime error
VishalMysore
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -138,11 +138,77 @@ def evaluate(example, treshold):
|
|
138 |
average_score_truth = "{:.0%}".format(average_score_truth)
|
139 |
return average_score_predicted, predictions, labels, average_score_truth
|
140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
with gr.Blocks(theme=style) as demo:
|
142 |
with gr.Tab("Maya"):
|
143 |
gr.Markdown(title)
|
144 |
gr.Markdown(description)
|
145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
with gr.Tab("Mithya"):
|
147 |
gr.Markdown(title)
|
148 |
gr.Markdown(description)
|
@@ -177,8 +243,15 @@ with gr.Blocks(theme=style) as demo:
|
|
177 |
examples_dropdown.input(mirror, inputs=examples_dropdown, outputs=example_text)
|
178 |
submit.click(evaluate, inputs=[examples_dropdown, treshold], outputs=[label, highlighted_prediction, highlighted_ground_truth, label_ground_truth])
|
179 |
with gr.Tab("Router-Chain-Branch"):
|
180 |
-
gr.Markdown(
|
181 |
-
gr.Markdown(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
|
183 |
theme=gr.themes.Base()
|
184 |
demo.launch(debug=True)
|
|
|
138 |
average_score_truth = "{:.0%}".format(average_score_truth)
|
139 |
return average_score_predicted, predictions, labels, average_score_truth
|
140 |
|
141 |
+
from google.colab import userdata
|
142 |
+
OPENAI_API_KEY=userdata.get("OPENAI_API_KEY")
|
143 |
+
os.environ["OPENAI_API_KEY"]=str(OPENAI_API_KEY)
|
144 |
+
def read_html_file(file_path):
|
145 |
+
try:
|
146 |
+
with open(file_path, 'r', encoding='utf-8') as file:
|
147 |
+
html_content = file.read()
|
148 |
+
html_content = html_content.encode('ascii', 'ignore').decode('ascii')
|
149 |
+
html_content= html_content.replace("\n","")
|
150 |
+
html_content=re.sub( ">\s+<", "><" , html_content)
|
151 |
+
return html_content
|
152 |
+
except FileNotFoundError:
|
153 |
+
print(f"File not found: {file_path}")
|
154 |
+
return None
|
155 |
+
except Exception as e:
|
156 |
+
print(f"An error occurred: {str(e)}")
|
157 |
+
return None
|
158 |
+
def createQuestions(documents):
|
159 |
+
questions = mqag_model.generate(context=document, do_sample=True, num_questions=3)
|
160 |
+
|
161 |
+
return questions
|
162 |
+
def detect(context, summary):
|
163 |
+
score = mqag_model.score(candidate=summary, reference=context, num_questions=3, verbose=True)
|
164 |
+
return score
|
165 |
+
|
166 |
+
def summarize(document):
|
167 |
+
response = client.chat.completions.create(
|
168 |
+
model="gpt-3.5-turbo",
|
169 |
+
messages=[
|
170 |
+
{
|
171 |
+
"role": "system",
|
172 |
+
"content": "Summarize content you are provided with for a second-grade student."
|
173 |
+
},
|
174 |
+
{
|
175 |
+
"role": "user",
|
176 |
+
"content":document
|
177 |
+
}
|
178 |
+
],
|
179 |
+
temperature=0.7,
|
180 |
+
max_tokens=64,
|
181 |
+
top_p=1
|
182 |
+
)
|
183 |
+
return response.choices[0].message.content
|
184 |
+
def detectRag(document,rags):
|
185 |
+
options = sorted([word.capitalize() for word in rags.split(",")])
|
186 |
+
print(options)
|
187 |
+
questions = [{'question': "what is the main topic of this?", 'options': options}]
|
188 |
+
probs = mqag_model.answer(questions=questions, context=document)
|
189 |
+
print(probs[0])
|
190 |
+
return probs[0]
|
191 |
+
html_content = read_html_file("cookgpt.html")
|
192 |
with gr.Blocks(theme=style) as demo:
|
193 |
with gr.Tab("Maya"):
|
194 |
gr.Markdown(title)
|
195 |
gr.Markdown(description)
|
196 |
+
with gr.Row():
|
197 |
+
with gr.Column():
|
198 |
+
context = gr.TextArea(label="Context" , value=document)
|
199 |
+
questions = gr.TextArea(label="Questions")
|
200 |
+
createQuestiobBTN = gr.Button("Create Questions")
|
201 |
+
createQuestiobBTN.click(createQuestions, inputs=context, outputs=questions)
|
202 |
+
|
203 |
+
with gr.Row():
|
204 |
+
with gr.Column():
|
205 |
+
summaryTx = gr.TextArea(label="Summary" , value=summary)
|
206 |
+
createSummaryBTN = gr.Button("Create Summary")
|
207 |
+
createSummaryBTN.click(summarize, inputs=context, outputs=summaryTx)
|
208 |
+
score = gr.TextArea(label="Score")
|
209 |
+
detectHallucinate = gr.Button("Detect Hallucination")
|
210 |
+
detectHallucinate.click(detect, inputs=[context,summaryTx], outputs=score)
|
211 |
+
gr.HTML(html_content)
|
212 |
with gr.Tab("Mithya"):
|
213 |
gr.Markdown(title)
|
214 |
gr.Markdown(description)
|
|
|
243 |
examples_dropdown.input(mirror, inputs=examples_dropdown, outputs=example_text)
|
244 |
submit.click(evaluate, inputs=[examples_dropdown, treshold], outputs=[label, highlighted_prediction, highlighted_ground_truth, label_ground_truth])
|
245 |
with gr.Tab("Router-Chain-Branch"):
|
246 |
+
gr.Markdown(titleRAG)
|
247 |
+
gr.Markdown(descriptionRAG)
|
248 |
+
with gr.Row():
|
249 |
+
with gr.Column():
|
250 |
+
contextRAG = gr.TextArea(label="Context" , value=document)
|
251 |
+
ragDocuments = gr.TextArea(label="Comma Seperated RAG" , value="paneer,chicken,breakfast")
|
252 |
+
findRAGDocument = gr.Button("Detect Document")
|
253 |
+
rag = gr.TextArea(label="Rag Document to Look for")
|
254 |
+
findRAGDocument.click(detectRag, inputs=[contextRAG,ragDocuments], outputs=rag)
|
255 |
|
256 |
theme=gr.themes.Base()
|
257 |
demo.launch(debug=True)
|