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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -17
app.py CHANGED
@@ -3,7 +3,6 @@ import os
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,21 +48,6 @@ def CustomChatGPT(category, user_input):
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,
@@ -151,7 +135,8 @@ iface = gr.Interface(
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
 
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
  # Return the model's message
49
  return ChatGPT_reply
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  # Define the Gradio interface
52
  iface = gr.Interface(
53
  fn=CustomChatGPT,
 
135
  favicon_path="https://assets.bigcartel.com/theme_images/101321509/IMG_6002.png", # Favicon image URL
136
  allow_flagging="manual", # Enable flagging with manual control
137
  flagging_options=["Incorrect", "Ambiguous"], # Specify flagging options
138
+ flagging_callback=hf_writer
139
+
140
  )
141
 
142
  # Launch the interface with authentication