prithivMLmods commited on
Commit
0cff8ea
·
verified ·
1 Parent(s): c612937

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -23
app.py CHANGED
@@ -1,38 +1,81 @@
 
1
  import gradio as gr
2
 
 
3
 
4
- # Assign GPU to the overall spaces
5
- def main():
 
 
 
 
 
 
 
6
 
7
- # Define the components using the specified URLs
8
- with gr.Blocks() as chatbot:
9
- gr.HTML("<iframe src='https://huggingface.co/spaces/prithivMLmods/Mistral-7B-Instruct-v0.3' width='100%' height='1000px' style='border-radius: 8px;'></iframe>")
 
 
 
 
10
 
11
- with gr.Blocks() as imagegpt:
12
- gr.HTML("<iframe src='https://huggingface.co/spaces/prithivMLmods/ImageGPT-4XL' width='100%' height='1000px' style='border-radius: 8px;'></iframe>")
 
 
 
 
 
 
13
 
14
- with gr.Blocks() as imageengine4k:
15
- gr.HTML("<iframe src='https://huggingface.co/spaces/prithivMLmods/DALLE-4K' width='100%' height='1000px' style='border-radius: 8px;'></iframe>")
16
 
17
- with gr.Blocks() as imageengine2k:
18
- gr.HTML("<iframe src='https://huggingface.co/spaces/prithivMLmods/DALLE-2K' width='100%' height='1000px' style='border-radius: 8px;'></iframe>")
19
 
20
- with gr.Blocks() as mediadownloader:
21
- gr.HTML("<iframe src='https://huggingface.co/spaces/prithivMLmods/All-In-One-Downloader' width='100%' height='1000px' style='border-radius: 8px;'></iframe>")
 
 
22
 
23
- with gr.Blocks() as photofakes:
24
- gr.HTML("<iframe src='https://huggingface.co/spaces/prithivMLmods/Face-Swap-Roop' width='100%' height='1000px' style='border-radius: 8px;'></iframe>")
 
 
 
25
 
26
- # Assemble the components into a single Gradio interface
27
- with gr.Blocks(theme="xiaobaiyuan/theme_brief", title="GPT 4o") as demo:
28
- gr.Markdown("# GPT 4o")
29
- gr.TabbedInterface(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  [chatbot, imagegpt, imageengine4k, imageengine2k, mediadownloader, photofakes],
31
  ['ChatBot', 'ImageGPT', 'Image Engine 4K', 'Image Engine 2K', 'Media Downloader', 'PhotoFakes']
32
  )
33
 
34
- # Launch the demo
35
- demo.queue().launch(debug=True)
 
36
 
37
- # Run the main function
38
- main()
 
1
+ from huggingface_hub import InferenceClient
2
  import gradio as gr
3
 
4
+ client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
5
 
6
+ def format_prompt(message, history, system_prompt=None):
7
+ prompt = "<s>"
8
+ for user_prompt, bot_response in history:
9
+ prompt += f"[INST] {user_prompt} [/INST]"
10
+ prompt += f" {bot_response}</s> "
11
+ if system_prompt:
12
+ prompt += f"[SYS] {system_prompt} [/SYS]"
13
+ prompt += f"[INST] {message} [/INST]"
14
+ return prompt
15
 
16
+ def generate(
17
+ prompt, history, system_prompt=None, temperature=0.2, max_new_tokens=1024, top_p=0.95, repetition_penalty=1.0,
18
+ ):
19
+ temperature = float(temperature)
20
+ if temperature < 1e-2:
21
+ temperature = 1e-2
22
+ top_p = float(top_p)
23
 
24
+ generate_kwargs = dict(
25
+ temperature=temperature,
26
+ max_new_tokens=max_new_tokens,
27
+ top_p=top_p,
28
+ repetition_penalty=repetition_penalty,
29
+ do_sample=True,
30
+ seed=42,
31
+ )
32
 
33
+ formatted_prompt = format_prompt(prompt, history, system_prompt)
 
34
 
35
+ stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
36
+ output = ""
37
 
38
+ for response in stream:
39
+ output += response.token.text
40
+ yield output
41
+ return output
42
 
43
+ demo = gr.ChatInterface(
44
+ fn=generate,
45
+ title="",
46
+ theme="xiaobaiyuan/theme_brief"
47
+ )
48
 
49
+
50
+ # Define the components using the specified URLs
51
+ with gr.Blocks() as chatbot:
52
+ gr.HTML("<iframe src='https://huggingface.co/spaces/prithivMLmods/Mistral-7B-Instruct-v0.3' width='100%' height='1000px' style='border-radius: 8px;'></iframe>")
53
+
54
+ with gr.Blocks() as imagegpt:
55
+ gr.HTML("<iframe src='https://huggingface.co/spaces/prithivMLmods/ImageGPT-4XL' width='100%' height='1000px' style='border-radius: 8px;'></iframe>")
56
+
57
+ with gr.Blocks() as imageengine4k:
58
+ gr.HTML("<iframe src='https://huggingface.co/spaces/prithivMLmods/DALLE-4K' width='100%' height='1000px' style='border-radius: 8px;'></iframe>")
59
+
60
+ with gr.Blocks() as imageengine2k:
61
+ gr.HTML("<iframe src='https://huggingface.co/spaces/prithivMLmods/DALLE-2K' width='100%' height='1000px' style='border-radius: 8px;'></iframe>")
62
+
63
+ with gr.Blocks() as mediadownloader:
64
+ gr.HTML("<iframe src='https://huggingface.co/spaces/prithivMLmods/All-In-One-Downloader' width='100%' height='1000px' style='border-radius: 8px;'></iframe>")
65
+
66
+ with gr.Blocks() as photofakes:
67
+ gr.HTML("<iframe src='https://huggingface.co/spaces/prithivMLmods/Face-Swap-Roop' width='100%' height='1000px' style='border-radius: 8px;'></iframe>")
68
+
69
+ # Assemble the components into a single Gradio interface
70
+ with gr.Blocks(theme="xiaobaiyuan/theme_brief", title="GPT 4o") as demo:
71
+ gr.Markdown("# GPT 4o")
72
+ gr.TabbedInterface(
73
  [chatbot, imagegpt, imageengine4k, imageengine2k, mediadownloader, photofakes],
74
  ['ChatBot', 'ImageGPT', 'Image Engine 4K', 'Image Engine 2K', 'Media Downloader', 'PhotoFakes']
75
  )
76
 
77
+ # Launch the demo
78
+
79
+
80
 
81
+ demo.queue().launch(show_api=False)