stupidHIGH commited on
Commit
f38e4e6
·
1 Parent(s): 8e6601b

Add application file

Browse files
Files changed (2) hide show
  1. app.py +53 -11
  2. requirements.txt +1 -2
app.py CHANGED
@@ -1,15 +1,57 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
5
 
6
- def predict(image):
7
- predictions = pipeline(image)
8
- return {p["label"]: p["score"] for p in predictions}
9
 
10
- gr.Interface(
11
- predict,
12
- inputs=gr.inputs.Image(label="Upload hot dog candidate", type="filepath"),
13
- outputs=gr.outputs.Label(num_top_classes=2),
14
- title="Hot Dog? Or Not?",
15
- ).launch(server_name='127.0.0.1',server_port=7788)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import os, openai
3
 
 
4
 
5
+ conversation = []
 
 
6
 
7
+ class ChatGPT:
8
+
9
+
10
+ def __init__(self):
11
+ self.api_key = ""
12
+ self.messages = conversation
13
+ self.model = os.getenv("OPENAI_MODEL", default = "gpt-3.5-turbo")
14
+
15
+ def save_api_key(self, user_input0):
16
+ self.api_key = user_input0
17
+
18
+ def get_response(self, user_input):
19
+ openai.api_key = self.api_key
20
+ conversation.append({"role": "user", "content": user_input})
21
+
22
+
23
+ response = openai.ChatCompletion.create(
24
+ model=self.model,
25
+ messages = self.messages
26
+
27
+ )
28
+
29
+ conversation.append({"role": "assistant", "content": response['choices'][0]['message']['content']})
30
+
31
+ print("AI回答內容:")
32
+ print(response['choices'][0]['message']['content'].strip())
33
+
34
+
35
+
36
+ return response['choices'][0]['message']['content'].strip()
37
+
38
+
39
+ chatgpt = ChatGPT()
40
+
41
+
42
+ def greet(prompt, api_key):
43
+ chatgpt.save_api_key(api_key)
44
+
45
+ reply_text = chatgpt.get_response(prompt)
46
+
47
+ greeting = f"{reply_text}"
48
+
49
+ return greeting
50
+
51
+ demo = gr.Interface(
52
+ fn=greet,
53
+ inputs=["text", "text"],
54
+ outputs=["text"],
55
+ )
56
+
57
+ demo.launch()
requirements.txt CHANGED
@@ -1,3 +1,2 @@
1
  gradio
2
- transformers
3
- torch
 
1
  gradio
2
+ openai==0.27.0