Narchethan commited on
Commit
2d8d112
·
1 Parent(s): f5be8c4

mise a jourc

Browse files
Files changed (2) hide show
  1. app.py +70 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import InferenceClient
2
+ import gradio as gr
3
+
4
+ def hf_chat(api_key, system_prompt, user_prompt, temperature, max_tokens, top_p):
5
+ try:
6
+ # Initialize the Hugging Face Inference Client
7
+ client = InferenceClient(api_key=api_key)
8
+
9
+ # Prepare the messages
10
+ messages = [
11
+ {"role": "system", "content": system_prompt},
12
+ {"role": "user", "content": user_prompt}
13
+ ]
14
+
15
+ # Stream the response from the Hugging Face model
16
+ stream = client.chat.completions.create(
17
+ model="Qwen/Qwen2.5-72B-Instruct",
18
+ messages=messages,
19
+ temperature=temperature,
20
+ max_tokens=max_tokens,
21
+ top_p=top_p,
22
+ stream=True
23
+ )
24
+
25
+ # Concatenate the streamed content
26
+ output = ""
27
+ for chunk in stream:
28
+ output += chunk.choices[0].delta.content
29
+
30
+ return output
31
+
32
+ except Exception as e:
33
+ return f"Error: {str(e)}"
34
+
35
+ # Define the Gradio interface
36
+ with gr.Blocks() as demo:
37
+ gr.Markdown("""# history prof it is my first appli.
38
+ i am bad in history but to help me for my homework i makeing
39
+ a ai.""")
40
+
41
+ api_key_input = gr.Textbox(label="Hugging Face API Key", placeholder="Enter your Hugging Face API key", type="password")
42
+ system_prompt_input = gr.Textbox(label="ethan's history prof", value="You are a history professor 5e in FRENCH.", placeholder="you are a history professor 5e in FRENCH.")
43
+ user_prompt_input = gr.Textbox(label="user chat", placeholder="metez votre question ici.")
44
+
45
+
46
+ temperature_slider = gr.Slider(label="Temperature", minimum=0.0, maximum=1.0, value=0.7, step=0.1)
47
+ max_tokens_slider = gr.Slider(label="Max Tokens", minimum=10, maximum=2048, value=100, step=10)
48
+ top_p_slider = gr.Slider(label="Top P", minimum=0.1, maximum=1.0, value=0.7, step=0.1)
49
+
50
+ output = gr.Textbox(label="history prof 👨‍🏫")
51
+
52
+ generate_button = gr.Button("📖")
53
+
54
+ generate_button.click(
55
+ hf_chat,
56
+ inputs=[
57
+ api_key_input,
58
+ system_prompt_input,
59
+ user_prompt_input,
60
+ temperature_slider,
61
+ max_tokens_slider,
62
+ top_p_slider
63
+ ],
64
+ outputs=[output]
65
+ )
66
+
67
+ if __name__ == "__main__":
68
+ demo.launch()
69
+
70
+ #Merci papa de m'avoir offert cet ordi ❤️❤️❤️
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ requests
3
+ huggingface_hub