leochenliu commited on
Commit
7663944
·
1 Parent(s): 144bc2b

add maiyi v1

Browse files
Files changed (3) hide show
  1. __pycache__/app.cpython-310.pyc +0 -0
  2. app.py +9 -3
  3. req.txt +143 -0
__pycache__/app.cpython-310.pyc ADDED
Binary file (546 Bytes). View file
 
app.py CHANGED
@@ -1,7 +1,13 @@
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return "你好 "+name+"!!!"
 
 
 
 
5
 
6
- iface = gr.Interface(fn=greet,inputs="text", outputs="text")
 
7
  iface.launch()
 
1
  import gradio as gr
2
+ import requests
3
 
4
+ def gpt(prompt):
5
+ baixing_gpt_key=os.environ.get("BAIXING_GPT_KEY")
6
+ endpoint = "https://gpt.baixing.com/?p=%s&k=%s" % (prompt,baixing_gpt_key)
7
+ response = requests.get(endpoint)
8
+ output = response.json()['data']
9
+ return output
10
 
11
+
12
+ iface = gr.Interface(fn=gpt,inputs="text", outputs="text")
13
  iface.launch()
req.txt ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def classify_pdf(prompt):
2
+ openai_api_key = os.environ.get("OPENAI_API_KEY")
3
+ text = prompt
4
+ data = {
5
+ "prompt": text,
6
+ "model": "text-davinci-003",
7
+ "length": 200,
8
+ "stop": "."
9
+ }
10
+ endpoint = "https://api.openai.com/v1/engines/davinci/completions"
11
+ headers = {
12
+ "Content-Type": "application/json",
13
+ "Authorization": f"Bearer {openai_api_key}"
14
+ }
15
+ response = requests.post(endpoint, headers=headers, json=data)
16
+ summary_output.value = response.json()['choices'][0]['text']
17
+
18
+
19
+ prompt = gr.inputs.Textbox()
20
+ summary_output = gr.outputs.Textbox()
21
+
22
+ interface = gr.Interface(classify_pdf, inputs=prompt, outputs=summary_output)
23
+ interface.launch()
24
+ intf.launch(inline=True)
25
+
26
+
27
+
28
+
29
+
30
+ https://gpt.baixing.com/?p=huggingfaceSpace中如何发出requests请求到别的网站,请用python代码来演示&k=NHSXKDRB
31
+
32
+
33
+ import os
34
+ import openai
35
+ import gradio as gr
36
+
37
+ #if you have OpenAI API key as an environment variable, enable the below
38
+ #openai.api_key = os.getenv("OPENAI_API_KEY")
39
+
40
+ #if you have OpenAI API key as a string, enable the below
41
+ openai.api_key = "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"
42
+
43
+ start_sequence = "\nAI:"
44
+ restart_sequence = "\nHuman: "
45
+
46
+ prompt = "Input text here"
47
+
48
+ def openai_create(prompt):
49
+
50
+ response = openai.Completion.create(
51
+ model="text-davinci-003",
52
+ prompt=prompt,
53
+ temperature=0.9,
54
+ max_tokens=150,
55
+ top_p=1,
56
+ frequency_penalty=0,
57
+ presence_penalty=0.6,
58
+ stop=[" Human:", " AI:"]
59
+ )
60
+
61
+ return response.choices[0].text
62
+
63
+
64
+
65
+ def chatgpt_clone(input, history):
66
+ history = history or []
67
+ s = list(sum(history, ()))
68
+ s.append(input)
69
+ inp = ' '.join(s)
70
+ output = openai_create(inp)
71
+ history.append((input, output))
72
+ return history, history
73
+
74
+
75
+ block = gr.Blocks()
76
+
77
+
78
+ with block:
79
+ gr.Markdown("""<h1><center>Sammy AI</center></h1>
80
+ """)
81
+ chatbot = gr.Chatbot()
82
+ message = gr.Textbox(placeholder=prompt)
83
+ state = gr.State()
84
+ submit = gr.Button("SEND")
85
+ submit.click(chatgpt_clone, inputs=[message, state], outputs=[chatbot, state])
86
+
87
+ block.launch(debug = True)
88
+ import os
89
+ import openai
90
+ import gradio as gr
91
+
92
+ #if you have OpenAI API key as an environment variable, enable the below
93
+ #openai.api_key = os.getenv("OPENAI_API_KEY")
94
+
95
+ #if you have OpenAI API key as a string, enable the below
96
+ openai.api_key = "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"
97
+
98
+ start_sequence = "\nAI:"
99
+ restart_sequence = "\nHuman: "
100
+
101
+ prompt = "Input text here"
102
+
103
+ def openai_create(prompt):
104
+
105
+ response = openai.Completion.create(
106
+ model="text-davinci-003",
107
+ prompt=prompt,
108
+ temperature=0.9,
109
+ max_tokens=150,
110
+ top_p=1,
111
+ frequency_penalty=0,
112
+ presence_penalty=0.6,
113
+ stop=[" Human:", " AI:"]
114
+ )
115
+
116
+ return response.choices[0].text
117
+
118
+
119
+
120
+ def chatgpt_clone(input, history):
121
+ history = history or []
122
+ s = list(sum(history, ()))
123
+ s.append(input)
124
+ inp = ' '.join(s)
125
+ output = openai_create(inp)
126
+ history.append((input, output))
127
+ return history, history
128
+
129
+
130
+ block = gr.Blocks()
131
+
132
+
133
+ with block:
134
+ gr.Markdown("""<h1><center>Sammy AI</center></h1>
135
+ """)
136
+ chatbot = gr.Chatbot()
137
+ message = gr.Textbox(placeholder=prompt)
138
+ state = gr.State()
139
+ submit = gr.Button("SEND")
140
+ submit.click(chatgpt_clone, inputs=[message, state], outputs=[chatbot, state])
141
+
142
+ block.launch(debug = True)
143
+