wasmdashai commited on
Commit
c1d1caf
ยท
verified ยท
1 Parent(s): 216e1e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -3
app.py CHANGED
@@ -1,7 +1,67 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  demo.launch()
 
1
  import gradio as gr
2
+ import os
3
+ import google.generativeai as genai
4
+ generation_config = {
5
+ "temperature": 1,
6
+ "top_p": 0.95,
7
+ "top_k": 40,
8
+ "max_output_tokens": 8192,
9
+ "response_mime_type": "text/plain",
10
+ }
11
 
12
+ def create_chat_session():
13
+ chat_session = Model.start_chat(
14
+ history=[
15
+ {
16
+ "role": "user",
17
+ "parts": [
18
+ "ุงู„ุณู„ุงู… ุนู„ูŠูƒู… ูƒูŠู ุงู„ุญุงู„\n",
19
+ ],
20
+ },
21
+ {
22
+ "role": "model",
23
+ "parts": [
24
+ "ูˆุนู„ูŠูƒู… ุงู„ุณู„ุงู… ูˆุฑุญู…ุฉ ุงู„ู„ู‡ ูˆุจุฑูƒุงุชู‡. ุจุฎูŠุฑุŒ ูˆุงู„ุญุงู„ ู…ุนูƒุŸ\n",
25
+ ],
26
+ },
27
+ ]
28
+ )
29
+ return chat_session
30
 
31
+
32
+ def get_answer_ai(text):
33
+ global AI
34
+ try:
35
+ response = AI.send_message(text)
36
+ return response.text
37
+
38
+
39
+ except :
40
+ AI=create_chat_session()
41
+ response = AI.send_message(text)
42
+ return response.text
43
+ AI=None
44
+ Model=None
45
+ print(response.text)
46
+ isActive="";
47
+ def greet(text,key):
48
+ global key
49
+ global Model
50
+ global AI
51
+ if key!="":
52
+ genai.configure(api_key=key)
53
+ Model = genai.GenerativeModel(
54
+ model_name="gemini-1.5-flash-8b",
55
+ generation_config=generation_config,
56
+ )
57
+ isActive=key
58
+ AI=create_chat_session()
59
+
60
+
61
+
62
+
63
+
64
+ return get_answer_ai(text)
65
+
66
+ demo = gr.Interface(fn=greet, inputs=["text","text"], outputs="text")
67
  demo.launch()