fudii0921 commited on
Commit
fe3a981
·
verified ·
1 Parent(s): c7ff072

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -74
app.py CHANGED
@@ -15,82 +15,11 @@ co_rerank = cohere.ClientV2(os.environ.get("COHERE_API_KEY"))
15
 
16
  vectored = None
17
 
18
- dataid = requests.get("https://www.ryhintl.com/dbjson/getjson?sqlcmd=select * from company_matters")
19
-
20
- data_str = dataid.content.decode('utf-8')
21
- data = json.loads(data_str)
22
-
23
- '''def decode_text(data):
24
- for item in data:
25
- item['text'] = item['text'].encode('latin1').decode('utf-8') # latin1でエンコード、UTF-8でデコード
26
- return data'''
27
-
28
- # デコード関数
29
- def decode_text(data):
30
- for item in data:
31
- try:
32
- # latin1 でデコードし、utf-8に変換
33
- item['text'] = item['text'].encode('latin1').decode('utf-8')
34
- except UnicodeDecodeError as e:
35
- print(f"エラー: {e}")
36
- item['text'] = "[デコード失敗]"
37
- return data
38
-
39
- '''def upload_html_to_server(file_path, url):
40
- with open(file_path, "rb") as file:
41
- # ファイルをアップロードする
42
- response = requests.post(url, files={"file": file})
43
- return response.status_code, response.text
44
-
45
- def upload_text_to_server(text, url):
46
- # テキストを送信
47
- response = requests.post(url, data={"content": text})
48
- return response.status_code, response.text
49
-
50
- # 自然言語にする関数
51
- def json_to_text(data):
52
- final_context = ""
53
- for item in data:
54
- text = (
55
- f"タイトル: {item['caption']}\n"
56
- f"表題: {item['title']}\n"
57
- f"詳細: {item['content']}\n"
58
- f"日付: {item['date']}\n"
59
- )
60
- final_context += text + "\n" # 結果を連結
61
-
62
- #last_content = "<html>\n<head>\n<title>会議議事録</title>\n</head>\n<body>\n"+final_context+"</body>\n</html>"
63
- last_content = final_context
64
-
65
- file_name = "output_cm.html"
66
- with open(file_name, "w", encoding="utf-8") as file:
67
- file.write(last_content)
68
-
69
- # サーバーURLを指定
70
- server_url = "https://www.ryhintl.com/company_matters.php" # 実際のアップロード先のURLに置き換えてね
71
-
72
- # アップロード実行
73
- status, response_text = upload_text_to_server(last_content, server_url)
74
- print(f"アップロードのステータス: {status}")
75
- print(f"レスポンス: {response_text}")
76
-
77
- return final_context
78
-
79
- # 実行例
80
- result = json_to_text(data)
81
-
82
- '''
83
-
84
  raw_documents = [
85
- {"title": "バグダードの戦い", "url": "https://ja.wikipedia.org/wiki/バグダードの戦い"},
86
  {"title": "2006年トリノオリンピック", "url": "https://ja.wikipedia.org/wiki/2006年トリノオリンピック"},
87
- {"title": "ドレッドノート_(戦艦)", "url": "https://ja.wikipedia.org/wiki/ドレッドノート_(戦艦)"},
88
- {"title": "えひめ丸事故", "url": "https://ja.wikipedia.org/wiki/えひめ丸事故"},
89
- {"title": "会議議事録", "url": "https://www.ryhintl.com/reqfiles/company_matters/cm_output.html"}
90
  ]
91
 
92
- #raw_documents = [{"title": "会議議事録", "url": "https://www.ryhintl.com/reqfiles/company_matters/cm_output.html"}]
93
-
94
  # あなたのクラスとロジックをここに統合します
95
  class Vectorstore:
96
 
@@ -207,8 +136,6 @@ vectorstore = Vectorstore(raw_documents)
207
  # Gradioの関数
208
  def search(query):
209
  results = vectorstore.retrieve(query)
210
- decoded_data = decode_text(results)
211
- print("decoded_data:",decoded_data)
212
  return "\n\n".join([f"**Title**: {r['title']}\n**Text**: {r['text']}\n**URL**: {r['url']}" for r in decoded_data])
213
 
214
  # Gradioインターフェース
 
15
 
16
  vectored = None
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  raw_documents = [
 
19
  {"title": "2006年トリノオリンピック", "url": "https://ja.wikipedia.org/wiki/2006年トリノオリンピック"},
20
+ {"title": "生成AI", "url": "https://ja.wikipedia.org/wiki/生成的人工知能"}
 
 
21
  ]
22
 
 
 
23
  # あなたのクラスとロジックをここに統合します
24
  class Vectorstore:
25
 
 
136
  # Gradioの関数
137
  def search(query):
138
  results = vectorstore.retrieve(query)
 
 
139
  return "\n\n".join([f"**Title**: {r['title']}\n**Text**: {r['text']}\n**URL**: {r['url']}" for r in decoded_data])
140
 
141
  # Gradioインターフェース