Spaces:
Sleeping
Sleeping
shumpei
commited on
Commit
·
71edbbe
1
Parent(s):
7559985
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""app.ipynb
|
3 |
+
|
4 |
+
Automatically generated by Colaboratory.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/1D-iexFe9RSsGXN4BhAqS--aCPbsTe6Bj
|
8 |
+
"""
|
9 |
+
|
10 |
+
from google.colab import drive
|
11 |
+
drive.mount('/content/drive')
|
12 |
+
|
13 |
+
!pip install gradio
|
14 |
+
|
15 |
+
import csv
|
16 |
+
import gradio as gr
|
17 |
+
|
18 |
+
dataset_file = "test.csv"
|
19 |
+
|
20 |
+
def create_dataset(question, output, input="", username=""):
|
21 |
+
# データセットの追加回数をカウントする変数
|
22 |
+
count = 0
|
23 |
+
|
24 |
+
# CSVファイルにデータを書き込む
|
25 |
+
with open(dataset_file, 'a', newline='') as file:
|
26 |
+
writer = csv.writer(file)
|
27 |
+
writer.writerow([question, input, output, username])
|
28 |
+
|
29 |
+
# データセットの追加回数をカウント
|
30 |
+
with open(dataset_file, 'r') as file:
|
31 |
+
reader = csv.reader(file)
|
32 |
+
for row in reader:
|
33 |
+
if row[3] == username: # ユーザー名でフィルタリング
|
34 |
+
count += 1
|
35 |
+
|
36 |
+
# データセットの追加回数をメッセージとして返す
|
37 |
+
return f"{username}さんは、データセットを合計 {count} 回作成しました!ありがとうございます!"
|
38 |
+
|
39 |
+
# 入力インターフェースを作成
|
40 |
+
inputs = [
|
41 |
+
gr.inputs.Textbox(label="質問", lines=2),
|
42 |
+
gr.inputs.Textbox(label="回答"),
|
43 |
+
gr.inputs.Textbox(label="入力 (オプション)"),
|
44 |
+
gr.inputs.Textbox(label="ユーザー名")
|
45 |
+
]
|
46 |
+
|
47 |
+
# 出力インターフェースを作成
|
48 |
+
output = gr.outputs.Textbox(label="ステータス")
|
49 |
+
|
50 |
+
# インターフェースを作成
|
51 |
+
interface = gr.Interface(fn=create_dataset, inputs=inputs, outputs=output)
|
52 |
+
|
53 |
+
# インターフェースを起動
|
54 |
+
interface.launch(share = True)
|