CannaTech commited on
Commit
bf06138
·
1 Parent(s): 866bdae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -3
app.py CHANGED
@@ -3,6 +3,7 @@ import os
3
  import openai
4
  import gradio as gr
5
  import json
 
6
 
7
  # Set the OpenAI API key
8
  openai.api_key = os.getenv("OPENAI_API_KEY")
@@ -48,6 +49,21 @@ def CustomChatGPT(category, user_input):
48
  # Return the model's message
49
  return ChatGPT_reply
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  # Define the Gradio interface
52
  iface = gr.Interface(
53
  fn=CustomChatGPT,
@@ -133,9 +149,9 @@ iface = gr.Interface(
133
  on growing your business!""", # Article text
134
  thumbnail="https://assets.bigcartel.com/theme_images/101321509/IMG_6002.png", # Thumbnail image URL
135
  favicon_path="https://assets.bigcartel.com/theme_images/101321509/IMG_6002.png", # Favicon image URL
136
- allow_flagging="manual",
137
- flagging_callback=hf_writer
138
-
139
  )
140
 
141
  # Launch the interface with authentication
 
3
  import openai
4
  import gradio as gr
5
  import json
6
+ import csv
7
 
8
  # Set the OpenAI API key
9
  openai.api_key = os.getenv("OPENAI_API_KEY")
 
49
  # Return the model's message
50
  return ChatGPT_reply
51
 
52
+ # Function to save flagged data to a Hugging Face Dataset using a token
53
+ class HuggingFaceDatasetSaver:
54
+ def __init__(self, dataset_name, huggingface_token):
55
+ self.dataset_name = dataset_name
56
+ self.huggingface_token = huggingface_token
57
+
58
+ def save_flagged_data(self, data):
59
+ from datasets import Dataset, FileSystemDataset
60
+
61
+ dataset = Dataset.from_dict(data)
62
+
63
+ # Write the dataset to Hugging Face using the provided token
64
+ fs_dataset = FileSystemDataset(self.dataset_name, data_files={self.dataset_name: dataset}, token=self.huggingface_token)
65
+ fs_dataset.save_to_disk()
66
+
67
  # Define the Gradio interface
68
  iface = gr.Interface(
69
  fn=CustomChatGPT,
 
149
  on growing your business!""", # Article text
150
  thumbnail="https://assets.bigcartel.com/theme_images/101321509/IMG_6002.png", # Thumbnail image URL
151
  favicon_path="https://assets.bigcartel.com/theme_images/101321509/IMG_6002.png", # Favicon image URL
152
+ allow_flagging="manual", # Enable flagging with manual control
153
+ flagging_options=["Incorrect", "Ambiguous"], # Specify flagging options
154
+ flagging_callback=HuggingFaceDatasetSaver("CannaTech/Flagged", os.getenv("HF_TOKEN")).save_flagged_data # Save flagged data to Hugging Face Dataset using token
155
  )
156
 
157
  # Launch the interface with authentication