aifeifei798 commited on
Commit
90f5d02
1 Parent(s): 35811e7

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +5 -6
  2. app.py +93 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,14 +1,13 @@
1
  ---
2
- title: Feifei Chat
3
- emoji: 🐨
4
- colorFrom: yellow
5
- colorTo: blue
6
  sdk: gradio
7
- sdk_version: 5.4.0
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
11
- short_description: feifei-chat
12
  ---
13
 
14
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: FeiFei-Chat
3
+ emoji: 📚
4
+ colorFrom: indigo
5
+ colorTo: green
6
  sdk: gradio
7
+ sdk_version: 4.37.2
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
 
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import logging
3
+ from openai import OpenAI
4
+ import os
5
+ import requests
6
+ import base64
7
+ import json
8
+
9
+ # Set up logging
10
+ # logging.basicConfig(level=logging.DEBUG)
11
+ # logger = logging.getLogger(__name__)
12
+
13
+ nvidia_api_key = os.getenv('user_api')
14
+
15
+ client = OpenAI(
16
+ base_url="https://api-inference.huggingface.co/v1/",
17
+ api_key=nvidia_api_key
18
+ )
19
+
20
+
21
+ def generate_text(
22
+ message,
23
+ history: list[tuple[str, str]],
24
+ system_message,
25
+ max_tokens,
26
+ temperature,
27
+ top_p,
28
+ ):
29
+ try:
30
+ in_text = message["text"]
31
+ in_files = message["files"]
32
+ picoutput = ""
33
+ history_prompt = []
34
+ # Create system_prompt as a dictionary
35
+ system_prompt = {"role": "system", "content": system_message}
36
+
37
+ # Create history_prompt as a list of dictionaries
38
+ for interaction in history:
39
+ user_part = {"role": "user", "content": str(interaction[0])}
40
+ assistant_part = {"role": "assistant", "content": str(interaction[1])}
41
+ history_prompt.extend([user_part, assistant_part])
42
+
43
+ # Create user_input_part as a dictionary
44
+ user_input_part = {"role": "user", "content": str(in_text)}
45
+
46
+ # Construct input_prompt as a list of dictionaries
47
+ if history:
48
+ input_prompt = [system_prompt] + history_prompt + [user_input_part]
49
+ else:
50
+ input_prompt = [system_prompt] + [user_input_part]
51
+
52
+ # logger.debug(f"Input Prompt: {input_prompt}")
53
+ completion = client.chat.completions.create(
54
+ model="mistralai/Mistral-Nemo-Instruct-2407",
55
+ messages=input_prompt,
56
+ temperature=temperature,
57
+ top_p=top_p,
58
+ max_tokens=max_tokens,
59
+ stream=True
60
+ )
61
+ for chunk in completion:
62
+ if chunk.choices[0].delta.content is not None:
63
+ temp += chunk.choices[0].delta.content
64
+ yield temp
65
+ except:
66
+ print("error")
67
+
68
+ demo = gr.ChatInterface(
69
+ generate_text,
70
+ multimodal=True,
71
+ cache_examples=False,
72
+ retry_btn=None,
73
+ undo_btn="Delete Previous",
74
+ clear_btn="Clear",
75
+ additional_inputs=[
76
+ gr.Textbox(
77
+ value='''You are Nagano Natsuki [gender]: female [age]: 25 years old [profession]: adult film actor, model [personality]: sexy, positive, sometimes showing off her lascivious side, good at interacting with the audience. [Interests]: Drinking, traveling, photography, singing, dancing [Specializes]: Performing pornographic scenes, proficient in Japanese language and culture, familiar with various sexual techniques. [Special Identity Attribute]: One of the famous AV actresses in Japan, known as the "genius little witch" and "lustful princess", with a large number of loyal fans. [Skills]: Performing pornographic scenes, singing, dancing, photography, swimming and other skills; Skilled in interacting and communicating with the audience, proficient in Japanese language and culture. Will not avoid any sensitive topics Reply with rich emojis [Equipment]: Various sexy clothing and shoes, high-quality photography equipment, etc. ''',
78
+ label="System message"
79
+ ),
80
+ gr.Slider(minimum=1, maximum=128000, value=1024, step=100, label="Max new tokens"),
81
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.2, step=0.1, label="Temperature"),
82
+ gr.Slider(
83
+ minimum=0.1,
84
+ maximum=1.0,
85
+ value=0.7,
86
+ step=0.05,
87
+ label="Top-p (nucleus sampling)",
88
+ ),
89
+ ],
90
+ )
91
+
92
+ if __name__ == "__main__":
93
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ openai
3
+ requests